<Style x:Key="ScaleStyle" TargetType="{x:Type FrameworkElement}">
<Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform />
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding IsShowing}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation From="0.5" To="1" Duration="0:0:0.2" Storyboard.TargetProperty="RenderTransform.ScaleX" />
<DoubleAnimation From="0.5" To="1" Duration="0:0:0.2" Storyboard.TargetProperty="RenderTransform.ScaleY" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
<DataTrigger Binding="{Binding IsShowing}" Value="False">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation To="0.5" Duration="0:0:0.1" Storyboard.TargetProperty="RenderTransform.ScaleX"/>
<DoubleAnimation To="0.5" Duration="0:0:0.1" Storyboard.TargetProperty="RenderTransform.ScaleY"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
现在它总是启动第二个数据触发器,而它应该启动第一个数据触发器,因为IsShowing的实际值是True,直到我按下关闭按钮,所以我不知道为什么这会忽略该值并且它总是触发第二个数据触发器。
任何帮助将不胜感激。谢谢:))
答案 0 :(得分:0)
试试这个
<Style x:Key="ScaleStyle" TargetType="{x:Type FrameworkElement}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsShowing,RelativeSource={RelativeSource Self}}" Value="True">
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="1" ScaleY="1" />
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding IsShowing,RelativeSource={RelativeSource Self}}" Value="False">
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="0.1" ScaleY="0.1" />
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
答案 1 :(得分:0)
而不是创建另一个触发器,将其他故事板放在 DataTrigger.ExitActions
中,它将正常工作。
<DataTrigger Binding="{Binding IsShowing}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation From="0.5" To="1" Duration="0:0:0.2"
Storyboard.TargetProperty="RenderTransform.ScaleX" />
<DoubleAnimation From="0.5" To="1" Duration="0:0:0.2"
Storyboard.TargetProperty="RenderTransform.ScaleY" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation To="0.5" Duration="0:0:0.1"
Storyboard.TargetProperty="RenderTransform.ScaleX"/>
<DoubleAnimation To="0.5" Duration="0:0:0.1"
Storyboard.TargetProperty="RenderTransform.ScaleY"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>