gpt4 book ai didi

wpf - ActualWidth 作为 From WPF 动画的值

转载 作者:行者123 更新时间:2023-12-04 14:09:24 24 4
gpt4 key购买 nike

为什么我不能引用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 属性)。尝试找到祖先 Button反而

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>

关于wpf - ActualWidth 作为 From WPF 动画的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5154205/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com