gpt4 book ai didi

c# - 是否可以在控件的数据绑定(bind)更改时为转换设置动画?

转载 作者:行者123 更新时间:2023-11-30 22:05:00 24 4
gpt4 key购买 nike

我们有一个 UserControl,它主要包括一个绑定(bind)到项目列表的 XamTileManager(实际控件不重要)。当绑定(bind)发生变化时,我们希望使用任意动画为新旧数据之间的转换设置动画。这在 WPF 中通常可行吗?

替代方案当然是拥有两个 UserControl 并为它们之间的变化设置动画,但我们希望尽可能避免这种情况。

最佳答案

您可以在带有 Storyboard的项目中放置触发器。当数据发生变化时,触发器将触发并启动 Storyboard 动画。我找到了这个用于数据绑定(bind)文本 block 的示例:

<TextBlock x:Name="tbMessage" Text="{Binding Path=StatusBarText, NotifyOnTargetUpdated=True}">
<TextBlock.Triggers>
<EventTrigger RoutedEvent="Binding.TargetUpdated">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:0" To="1.0" />
<DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:2" From="1.0" To="0.0" BeginTime="0:0:5" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>

( source )

如果这不是您想要的,您可以使用 Binding.TargetUpdated 编写自己的动画。事件。

关于c# - 是否可以在控件的数据绑定(bind)更改时为转换设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24678996/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com