Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
作为来自WPF动画的值的实际宽度_Wpf_Actualwidth - Fatal编程技术网

作为来自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>

把鼠标放在我身上摇晃