1 回答
TA贡献1795条经验 获得超7个赞
这对我来说效果很好,即Opacity设置为0然后在ListViewItem加载后进行动画处理:
<ListView x:Name="lstDummies">
<ListView.Resources>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="Opacity" Value="0" />
<Style.Triggers>
<EventTrigger RoutedEvent="Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:2">
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Style.Triggers>
</Style>
</ListView.Resources>
<ListView.ItemsPanel >
<ItemsPanelTemplate >
<UniformGrid VerticalAlignment="Top" HorizontalAlignment="Left" Columns="17"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<Rectangle Width="50" Height="50" Fill="Green" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
如果您希望项目一项一项地淡入,您应该在调用之间引入延迟Add:
private async void Button_Click(object sender, RoutedEventArgs e)
{
for (int i = 0; i < 100; i++)
{
lstDummies.Items.Add(new dummyItem());
await Task.Delay(100);
}
}
- 1 回答
- 0 关注
- 95 浏览
添加回答
举报