作为来自WPF动画的值的实际宽度
为什么我不能引用作为来自WPF动画的值的实际宽度,wpf,actualwidth,Wpf,Actualwidth,为什么我不能引用ActualWidth作为我可以在代码中使用的值 XAML: <StackPanel> <Button x:Name="cmdVibrate" HorizontalAlignment="Center"> <Button.Triggers> <EventTrigger RoutedEvent="Button.MouseEnter">
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>
把鼠标放在我身上摇晃
RelativeSource={RelativeSource Mode=Self}
可能会引用DoubleAnimation
(它没有ActualWidth
属性)。尝试查找祖先按钮
From="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}},
Path=ActualWidth}"
Xaml
<StackPanel>
<Button x:Name="cmdVibrate" HorizontalAlignment="Center">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.MouseEnter">
<BeginStoryboard>
<Storyboard >
<DoubleAnimation From="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}}, 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>
把鼠标放在我身上摇晃