1 回答

TA貢獻(xiàn)1795條經(jīng)驗(yàn) 獲得超7個(gè)贊
這對(duì)我來(lái)說(shuō)效果很好,即Opacity設(shè)置為0然后在ListViewItem加載后進(jìn)行動(dòng)畫處理:
<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>
如果您希望項(xiàng)目一項(xiàng)一項(xiàng)地淡入,您應(yīng)該在調(diào)用之間引入延遲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 關(guān)注
- 141 瀏覽
添加回答
舉報(bào)