gpt4 book ai didi

c# - 在 DataTrigger WPF 上开始 Storybard

转载 作者:太空宇宙 更新时间:2023-11-03 21:34:33 24 4
gpt4 key购买 nike

我正在为我的应用程序启动时使用过渡动画。

<Storyboard x:Key="InTransition">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ContentGrid" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:05" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:05.5000000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ContentGrid" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="-72"/>
<SplineDoubleKeyFrame KeyTime="00:00:05" Value="-157"/>
<SplineDoubleKeyFrame KeySpline="0.5,0,0.5,1" KeyTime="00:00:05.5000000" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>

如果我将它作为 EventTrigger RoutedEvent="FrameworkElement.Loaded" 启动,效果很好,但我想将它绑定(bind)到我的 viewModel 上名为 IsInitialized 的属性。问题是 Windows.Triggers 不允许 DataTrigger

我该怎么做?

最佳答案

您是正确的,您不能在 Triggers 集合中使用 DataTrigger。相反,您需要使用 UIElement.Style.Triggers 集合。然后您可以使用 DataTrigger.EnterActions 元素来承载您的 Storyboard 元素:

<Window ...>
<Window.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding YourProperty}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard ... />
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Style>
</Window>

关于c# - 在 DataTrigger WPF 上开始 Storybard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22409177/

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