我已经实现了一些动画Expander.Expanded
,这个工作正常,但类似的动画不起作用Expander.Collapsed
。
XAML:
<Border Name="bor3" >
<Border.Triggers>
<EventTrigger RoutedEvent="Expander.Expanded" SourceName="exp3">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
From="0"
To="1"
Duration="0:0:0.25"
Storyboard.TargetName="gr3"
Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="Expander.Collapsed" SourceName="exp3" >
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
From="1"
To="0"
Duration="0:0:0.25"
Storyboard.TargetName="gr3"
Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Border.Triggers>
<Expander Name="exp3">
<Grid Name="gr3">
<Grid.LayoutTransform>
<ScaleTransform ScaleX="1" ScaleY="0"/>
</Grid.LayoutTransform>
<TextBlock >Test!</TextBlock>
</Grid>
</Expander>
</Border>
更新:
我已经Datatriggers
在控制旁边进行了测试,Style
但也有同样的问题:
<Border Name="bor3" >
<Expander Name="exp3">
<Grid Name="gr3">
<Grid.Style>
<Style TargetType="Grid">
<Style.Triggers>
<DataTrigger Binding="{Binding IsExpanded, RelativeSource={RelativeSource AncestorType=Expander}}" Value="true">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
From="0"
To="1"
Duration="0:0:0.25"
Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
From="1"
To="0"
Duration="0:0:0.25"
Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
<Grid.LayoutTransform>
<ScaleTransform ScaleX="1" ScaleY="0"/>
</Grid.LayoutTransform>
<TextBlock >Test!</TextBlock>
</Grid>
</Expander>
</Border>
什么是问题,什么是解决方案?!