将 XAML EventTrigger 转换为 C# 代码
谁能告诉我这在 C# 中会是什么样子?
<EventTrigger RoutedEvent="Button.Click" SourceName="btnSplit">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation From="0" To="1" Duration="0:0:0.25" Storyboard.TargetName="gridSplit" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)"/>
<DoubleAnimation From="1" To="0" Duration="0:0:0.25" Storyboard.TargetName="gridJoin" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
我不需要“RoatedEvent”部分,因为我想在用户以编程方式单击按钮时执行代码(Click-EventHandler)。首先调用 RoutedEvent 处理程序,这就是为什么我不能执行 if-否则,需要在代码隐藏中完成整个动画。
提前致谢!
孟菲斯
Can anyone tell me how this would look like in C#?
<EventTrigger RoutedEvent="Button.Click" SourceName="btnSplit">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation From="0" To="1" Duration="0:0:0.25" Storyboard.TargetName="gridSplit" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)"/>
<DoubleAnimation From="1" To="0" Duration="0:0:0.25" Storyboard.TargetName="gridJoin" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
I don't need the "RoutedEvent"-Part because I want to execute the Code when the User Clicks on a Button programmatically (Click-EventHandler).. The RoutedEvent Handler gets called first which is why I can't do a if-else and need to do the whole Animation in code-behind.
Thanks in advance!
MemphiZ
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了!
只需给情节提要一个 x:Name,然后像这样调用它:
Solved it!
Just give the Storyboard an x:Name and then call it like this: