wpf WPF按钮单击路由事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12833041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF Button click Routed Event
提问by Anshu Dutta
I am getting the following error when trying to execute a button clcik event from xaml
尝试从 xaml 执行按钮 clcik 事件时出现以下错误
<Button x:Name="myButton" Content="Surface History"
HorizontalAlignment="Right">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MyText"
Storyboard.TargetProperty="Text">
<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Hello" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
<TextBox Name="MyText" Text="Hi"/>
TextStoryboard.TargetPropertypath contains nonanimatable property Text.
TextStoryboard.TargetProperty路径包含不可动画的属性Text。
采纳答案by abhishek
Text property is Non Animatable dependency property. While creating the dependency property for Text, the UIMetaData IsAnimationProhibited property is set to true which prohibits the Text property to animate.
文本属性是不可动画的依赖属性。在为 Text 创建依赖属性时,UIMetaData IsAnimationProhibited 属性设置为 true,这会禁止 Text 属性进行动画处理。
So Text property cannot be animated. You need to manually set the text from Timer to get this behaviour.
所以 Text 属性不能被动画化。您需要手动设置 Timer 中的文本才能获得此行为。

