Я хочу, чтобы элементы, добавленные в мой ItemControl, обновляли высоту при их добавлении. Следующий пример, используя триггеры, выполнял эту работу, но я не мог заставить его работать с нефиксированной высотой для элементов (в этом случае 50).Анимация, не играющая с WPF VisualStateManager
<ItemsControl ItemsSource="{Binding Notifications}">
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type Notifications1:Notification}">
<Button x:Name="ItemButton"
ClipToBounds="True"
Height="0">
<Button.Template>
<ControlTemplate>
<Notifications:NotificationTile />
</ControlTemplate>
</Button.Template>
</Button>
<DataTemplate.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded"
SourceName="ItemButton">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Height"
Storyboard.TargetName="ItemButton"
Duration="0:0:0.5"
To="50" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ItemsControl.Resources>
Затем я попытался использовать VisualStateManager для выполнения анимации, так что плитка будет расти независимо от высоты они требовали. В приведенном ниже примере элементы добавляются с правильным размером, но анимация не выполняется. Я предполагаю, что EventTrigger даже не уволен?
Любые идеи высоко оценены!
<ItemsControl ItemsSource="{Binding Notifications}"
Width="230"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
HorizontalContentAlignment="Stretch">
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type Notifications1:Notification}">
<Button x:Name="ItemButton"
ClipToBounds="True"
Command="{Binding DataContext.ItemClicked, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"
CommandParameter="{Binding}"
Visibility="{Binding IsVisible, Converter={StaticResource boolToVisibilityConverter}}">
<Button.Template>
<ControlTemplate>
<Notifications:NotificationTile />
</ControlTemplate>
</Button.Template>
<VisualStateManager.CustomVisualStateManager>
<is:ExtendedVisualStateManager />
</VisualStateManager.CustomVisualStateManager>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup is:ExtendedVisualStateManager.UseFluidLayout="True">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:2" />
</VisualStateGroup.Transitions>
<VisualState x:Name="Collapsed">
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="(FrameworkElement.Height)"
Storyboard.TargetName="ItemButton"
Duration="0"
To="0" />
</Storyboard>
</VisualState>
<VisualState x:Name="Expanded">
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)"
Storyboard.TargetName="ItemButton">
<DiscreteDoubleKeyFrame KeyTime="0"
Value="NaN" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<i:Interaction.Triggers>
<i:EventTrigger SourceName="ItemButton"
EventName="(FrameworkElement.Loaded)">
<is:GoToStateAction StateName="Expanded" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</DataTemplate>
</ItemsControl.Resources>