我摸索了两天,在发布问题后5分钟就找到了解决方案。
没有使用
xf:Animations.StartWith
,而是添加了这个:
<ContentPresenter.LayoutTransform>
<ScaleTransform ScaleX="1" ScaleY="0" />
</ContentPresenter.LayoutTransform>
如果你想实现膨胀和收缩的动画,可以将其写在Trigger中。
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded" Value="True">
<Setter TargetName="ExpandSite" Property="xf:Animations.CombinedBinding" Value="True" />
<Setter TargetName="ExpandSite" Property="xf:Animations.Primary" Value="{xf:Animate BasedOn={StaticResource ScaleFromTop}, Event=None, Duration=300, TransformOn=Layout}" />
<Setter TargetName="ExpandSite" Property="xf:Animations.Secondary" Value="{xf:Animate BasedOn={StaticResource ScaleToTop}, Event=None, Duration=300, TransformOn=Layout}" />
</Trigger>
<Trigger Property="IsExpanded" Value="False">
<Setter TargetName="ExpandSite" Property="xf:Animations.CombinedBinding" Value="False" />
<Setter TargetName="ExpandSite" Property="xf:Animations.Primary" Value="{xf:Animate BasedOn={StaticResource ScaleFromBottom}, Event=None, Duration=300, TransformOn=Layout}" />
<Setter TargetName="ExpandSite" Property="xf:Animations.Secondary" Value="{xf:Animate BasedOn={StaticResource ScaleToBottom}, Event=None, Duration=300, TransformOn=Layout}" />
</Trigger>
</ControlTemplate.Triggers>