wpf - 动画列表框中新添加的项目
问题描述
我正在尝试将动画添加到列表框中新添加的项目和/或更改的项目,这是我到目前为止所做的:
<Style x:Key="ListBoxItemStyle4" TargetType="{x:Type ListBoxItem}">
<Setter Property="LayoutTransform">
<Setter.Value>
<ScaleTransform x:Name="transform" />
</Setter.Value>
</Setter>
<Style.Triggers>
<EventTrigger RoutedEvent="Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:2" />
<DoubleAnimation Storyboard.TargetProperty="LayoutTransform.ScaleY" From="0" Duration="0:0:.2"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Style.Triggers>
</Style>
这会为我的列表框中的每个项目设置动画。
解决方案
本文中解释了一个工作示例:
它通过 itemcontainerstyle 应用动画:
<ListBox ItemsSource="{Binding Messages}" BorderBrush="Transparent" Background="LightGray">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<ContentPresenter/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="LayoutTransform">
<Setter.Value>
<ScaleTransform/>
</Setter.Value>
</Setter>
<Style.Triggers>
<EventTrigger RoutedEvent="Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:1.2" FillBehavior="Stop" />
<DoubleAnimation Storyboard.TargetProperty="LayoutTransform.ScaleY" From="0" Duration="0:0:1.2" FillBehavior="Stop">
<DoubleAnimation.EasingFunction>
<BounceEase Bounces="2" Bounciness="6"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
还解决了删除前的动画。
推荐阅读
- python - 如何用月份绘制x轴?
- javascript - 如何清除 Jest 模拟实现以进行下一次测试?
- python - 更新 Jira 过滤器权限 - jira python
- android - 闪烁的安卓模拟器
- python - 为什么我无法在 Windows 10 上安装 rpy2 for Python?
- python - 我想从网站上抓取文章标题,但结果显示没有
- node.js - 如何在 cluster.task 中重用事件添加页面?(任务完成后不要关闭页面,并希望重复使用它)
- objective-c - UINavigationController:pushViewController 在 iOS 13 中不起作用,仍然在同一页面上
- python - 搜索部分单词并将其替换为正则表达式
- python - 如何提取a下的链接
- 带有特定类别的标签?