gpt4 book ai didi

WPF停止可见性的 Storyboard 已更改

转载 作者:行者123 更新时间:2023-12-04 03:17:56 24 4
gpt4 key购买 nike

我有一个带有 Storyboard的UserControl,并且我想在控件的“可见性”更改时停止动画。

我创建了一个Trigger来暂停动画并根据状态启动动画,但是我不断收到ArgumentException。

这是XAML:

<UserControl.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard x:Name="ProgressAnimation_BeginStoryboard" Storyboard="{StaticResource ProgressAnimation}"/>
</EventTrigger>
<Trigger Property="Control.Visibility" Value="Collapsed">
<PauseStoryboard BeginStoryboardName="ProgressAnimation_BeginStoryboard" />
</Trigger>
<Trigger Property="Control.Visibility" Value="Visible">
<ResumeStoryboard BeginStoryboardName="ProgressAnimation_BeginStoryboard" />
</Trigger>
</UserControl.Triggers>

这是异常(exception):

The value "System.Windows.Media.Animation.PauseStoryboard" is not of type "System.Windows.SetterBase" and cannot be used in this generic collection. Parameter name: value



我将如何在XAML中做到这一点?

谢谢,
劳尔

最佳答案

您可以使用控制模板来做到这一点:

<ControlTemplate>
... Control stuff here

<ControlTemplate.Triggers>
<Trigger Property="Visibility" Value="Visible">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource AnimationStoryboard}" x:Name="AnimationBeginStoryboard"/>
</Trigger.EnterActions>
<Trigger.ExitActions>
<RemoveStoryboard BeginStoryboardName="AnimationBeginStoryboard"/>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>

</ControlTemplate>

关于WPF停止可见性的 Storyboard 已更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2009880/

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