绑定到具有转换的可观察集合
本文关键字:观察 集合 转换 绑定 | 更新日期: 2023-09-27 18:37:26
我有绑定到ObservableCollection
的ItemsControl
在我的视图模型上,我只是插入对象,它就会弹出到 UI 上
我想展示过渡。例如,我希望此项目淡入,以便用户直观地注册此更改,假设它在 1 秒内发生。
我应该寻找什么?在 WPF 中是如何完成的?
编辑:
我想我需要某种动画,但我正在寻找的是没有编码的简单东西。普通 XAML 实现,是否内置任何内容?我尝试了TranslateTransform
和其他选择,但它没有任何作用。
<ItemsControl ItemsSource="{Binding Source={StaticResource TrucksSource}}">
<ItemsControl.RenderTransform>
<TranslateTransform />
</ItemsControl.RenderTransform>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding TruckId}" Background="Aqua"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
对于淡入,您可以在Loaded
事件上使用EventTrigger
来ContentPresenters
<ItemsControl ItemsSource="{Binding Source={StaticResource TrucksSource}}">
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Style.Triggers>
<EventTrigger RoutedEvent="Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard Storyboard.TargetProperty="Opacity">
<DoubleAnimation From="0.0"
To="1.0"
Duration="00:00:01"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Style.Triggers>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding TruckId}" Background="Aqua"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
阅读以下内容: http://msdn.microsoft.com/en-us/library/ms750596.aspx
您需要动画转换(最后一章)并将不透明度值从 1.0 更改为 0.0