使用XamlFlair制作WPF扩展器的动画

qhhrdooz  于 12个月前  发布在  其他
关注(0)|答案(2)|浏览(174)

我不知道如何用XamlFlair动画WPF扩展器。我最简单的模板(应该从上到下扩展和收缩到上):

<ControlTemplate TargetType="{x:Type Expander}">
    <DockPanel>
        <!-- EXPANDER HEADER -->
        <ToggleButton x:Name="ExpanderButton"
                        DockPanel.Dock="Top"
                        HorizontalContentAlignment="Stretch"
                        IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"
                        Content="Expand me"/>
        <!-- EXPANDER CONTENT -->
        <ContentPresenter x:Name="ExpanderContent"
                            DockPanel.Dock="Bottom"
                            xf:Animations.CombinedBinding="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"
                            xf:Animations.Primary="{xf:Animate BasedOn={StaticResource ScaleFromTop}, Event=None, TransformOn=Layout}"
                            xf:Animations.Secondary="{xf:Animate BasedOn={StaticResource ScaleToTop}, Event=None, TransformOn=Layout}"
                            xf:Animations.StartWith="{StaticResource ScaleToTop}">
        </ContentPresenter>
    </DockPanel>
</ControlTemplate>

字符串
问题是,无论IsExpanded的初始属性值是什么,Expander都会在开始时呈现扩展。当我添加xf:Animations.StartWith="{StaticResource ScaleToTop}"(或ScaleFromTop-无论哪一个)时,不仅没有解决这个问题,而且Expander的内容总是空白的。
有人知道如何让它像预期的那样工作吗?谢谢。

dba5bblo

dba5bblo1#

如果你想动画的膨胀和收缩,你可以写在触发器。

<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>

字符串

1u4esq0p

1u4esq0p2#

我挠头了两天,在发布问题后5分钟就想出了解决方案。
没有使用xf:Animations.StartWith,而是添加了这个:

<ContentPresenter.LayoutTransform>
    <ScaleTransform ScaleX="1" ScaleY="0" />
</ContentPresenter.LayoutTransform>

字符串

相关问题