Im trying to toggle an animation on height when a button "Show Details"/"Hide Details" is clicked and then back to its initial value when the button is clicked again.
I have a DataControls:DataForm with predefined style to start with, and I want the "Height"-property to animate to a larger value when the button is clicked.
The DataControl:Dataform looks like this.
<DataControls:DataForm x:Name="DataEdit"
Grid.Row="1"
ItemsSource="{Binding}"
Style="{DynamicResource CommonDataFormStyle}"
ContentLoaded="OnContentLoaded"
Height="150">
The button itself is inside the DataForm like this.
<DataControls:DataForm.ReadOnlyTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>...
<StackPanel Grid.Column="0" Grid.Row="0">
<Button Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl} }, Path=DataContext.ToggleDetailsCommand, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" x:Name="ToggleDetailsButton"
Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl} }, Path=DataContext.ToggleDetailsButtonText}"/>
...
I have only gotten this to work by usina a label called "Show Details" and an eventtrigger for RoutedEvent="Label.MouseLeftButtonDown" on one label to expand the details. And then have another label called "Hide Details" to togge the animation back again.
I have alsto tried puting this style on the button and with datatriggers trying to toggle the animation. This, however, does only animate the height of the button regardless of the StoryBoard.Target="{Binding ElementName=DataEdit}" attribute.
<Style TargetType="{x:Type Button}" x:Key="ExpandDetailsStyle" >
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl} }, Path=DataContext.IsOpened}" Value="true">
<DataTrigger.EnterActions>
<StopStoryboard BeginStoryboardName="EndAnimation" />
<BeginStoryboard Name="NewAnimation">
<Storyboard>
<DoubleAnimation Storyboard.Target="{Binding ElementName=DataEdit}" Storyboard.TargetProperty="Height" From="150" To="300" Duration="0:0:0.1" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
</DataTrigger.ExitActions>
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl} }, Path=DataContext.IsOpened}" Value="false">
<DataTrigger.EnterActions>
<StopStoryboard BeginStoryboardName="NewAnimation" />
<BeginStoryboard Name="EndAnimation">
<Storyboard>
<DoubleAnimation Storyboard.Target="{Binding ElementName=DataEdit}" Storyboard.TargetProperty="Height" From="300" To="150" Duration="0:0:0.1" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
Also I'm fairly new to WPF so forgive me if I left something out here. Im unable to put a new custom style on the DataForm since it is already using a common style, it wouldnt let me use the "BasedOn" attribute either.
The closest I've got is the animation of the button height, if I only could get it to animate the DataForm height property instead.
Thanks in advance