ActualWidth作为From WPF动画的值 [英] ActualWidth as value of From WPF animation

查看:82
本文介绍了ActualWidth作为From WPF动画的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我不能在代码中引用ActualWidth作为值.

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>

推荐答案

RelativeSource={RelativeSource Mode=Self}可能将引用DoubleAnimation(不具有ActualWidth属性).尝试找到祖先Button

RelativeSource={RelativeSource Mode=Self} will probably be refering to the DoubleAnimation (which doesn't have an ActualWidth property). Try to find the ancestor Button instead

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>

这篇关于ActualWidth作为From WPF动画的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆