Wpf 设置绑定到外部对象的双重动画
我有以下Wpf 设置绑定到外部对象的双重动画,wpf,xaml,storyboard,wpf-animation,Wpf,Xaml,Storyboard,Wpf Animation,我有以下样式,其中包含用于展开边框的动画: <Style TargetType="{x:Type Border}" x:Key="BorderAnimations"> <Setter Property="FlowDirection" Value="RightToLeft" /> <Style.Triggers> <EventTrigger RoutedEvent="MouseEnter"> &
样式
,其中包含用于展开边框的动画
:
<Style TargetType="{x:Type Border}" x:Key="BorderAnimations">
<Setter Property="FlowDirection" Value="RightToLeft" />
<Style.Triggers>
<EventTrigger RoutedEvent="MouseEnter">
<BeginStoryboard>
<Storyboard >
<DoubleAnimation
Storyboard.TargetProperty="Width"
BeginTime="0:0:0"
From="" To="420" Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="MouseLeave">
<BeginStoryboard>
<Storyboard >
<DoubleAnimation
Storyboard.TargetProperty="Width"
BeginTime="0:0:0"
From="420" To="90" Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
我已尝试将其设置为:
From="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}}, Path=ActualWidth}"
但它不起作用
注意:这些样式位于ResourceDictionary.xaml上。如何实现动画以获得此宽度
编辑:引发异常:
Cannot freeze this Storyboard timeline tree for use across threads.
你不能。故事板是可冻结的(一旦冻结,故事板必须保持不变)。但您可以在运行时以编程方式向控件添加情节提要。。。我理解。好的,把它作为一个答案。当我决定做什么时,我会发布我的解决方案,但实际上你回答了我的问题。。。
Cannot freeze this Storyboard timeline tree for use across threads.