可见性变化的故事板

时间:2011-10-18 09:09:50

标签: wpf xaml storyboard

我正在尝试使用它的可见性作为触发器来设置用户控件(在WPF中)的动画。我不确定我做错了什么,但它似乎没有做任何事DX(原谅我,我是新手)。

这就是我在MainWindow.xaml中的内容:

<local:toolbarDiscPlayback x:Name="Main_toolbarDisc" Grid.Row="2" Visibility="Collapsed" Style="{DynamicResource toolbarStyle}"/>

在我的代码背后,我有一个更改用户控件可见性的click事件:

Main_toolbarDisc.Visibility = Visibility.Visible;

哪一项都运作良好,但它不像我(希望我)在我的资源词典中告诉它的动画:

<Style x:Key="toolbarStyle" TargetType="{x:Type VALR:toolbarDiscPlayback}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type VALR:toolbarDiscPlayback}">
                <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True" RenderTransformOrigin="0.5,0.5">
                    <Border.RenderTransform>
                        <TransformGroup>
                            <TranslateTransform Y="0"/>
                        </TransformGroup>
                    </Border.RenderTransform>
                    <ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                </Border>
            </ControlTemplate>

        </Setter.Value>
    </Setter>

<Style.Triggers>
    <Trigger Property="Visibility" Value="Visible">
        <Trigger.EnterActions>
            <BeginStoryboard>
                <Storyboard >
                    <DoubleAnimation
                    Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)"
                    From="150" To="0"
                    DecelerationRatio="0.5"
                    Duration="00:00:01.000"/>
                </Storyboard>
            </BeginStoryboard>
        </Trigger.EnterActions>
    </Trigger>
</Style.Triggers>

</Style>

正如您将注意到的,到目前为止,我只为动画制作或“变得可见”这样做了。我非常积极,我只是在做一些愚蠢的事,或者没有做正确的事。

1 个答案:

答案 0 :(得分:0)

这是因为RenderTransform配置了Border,而不是实际的local:toolbarDiscPlayback

这种改变应该足够......

<Style x:Key="toolbarStyle"
    TargetType="{x:Type VALR:toolbarDiscPlayback}">
    <Setter Property="RenderTransform">
            <Setter.Value>
                 <TranslateTransform/>
            </Setter.Value>
    </Setter>         
    <Setter Property="Template">
       <Setter.Value>
         <ControlTemplate 
                 TargetType="{x:Type VALR:toolbarDiscPlayback}">
             <Border BorderBrush="{TemplateBinding BorderBrush}"
                     ... >                      
                  <ContentPresenter .... />
             </Border>
         </ControlTemplate>
       <Setter.Value>
    </Setter>
    <Style.Triggers> 
        ...
    </Style.Triggers> 
 </Style>