ActualWidth 作为 From WPF 动画的值
为什么我不能将 ActualWidth
引用为我可以在代码中使用的值。
XAML:
<StackPanel>
<Button x:Name="cmdVibrate" HorizontalAlignment="Center">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.MouseEnter">
<BeginStoryboard>
<Storyboard >
<DoubleAnimation From="{Binding RelativeSource={RelativeSource Mode=Self},Path=ActualWidth}" By="200" AutoReverse="True" Duration="0:0:1" Storyboard.TargetProperty="Width"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
Mouse over me to shake
</Button>
</StackPanel>
</Window>
Why can't I refer to ActualWidth
as a value from, which I was able to use in code.
XAML:
<StackPanel>
<Button x:Name="cmdVibrate" HorizontalAlignment="Center">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.MouseEnter">
<BeginStoryboard>
<Storyboard >
<DoubleAnimation From="{Binding RelativeSource={RelativeSource Mode=Self},Path=ActualWidth}" By="200" AutoReverse="True" Duration="0:0:1" Storyboard.TargetProperty="Width"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
Mouse over me to shake
</Button>
</StackPanel>
</Window>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
RelativeSource={RelativeSource Mode=Self}
可能会引用DoubleAnimation
(它没有ActualWidth
属性)。尝试查找祖先Button
而不是Xaml
RelativeSource={RelativeSource Mode=Self}
will probably be refering to theDoubleAnimation
(which doesn't have anActualWidth
property). Try to find the ancestorButton
insteadXaml