我正在嘗試使用它的可見性作爲觸發器來設置用戶控件(在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>
正如你會注意到的,迄今爲止,我只做了用於生成動畫或「可見」的動畫。我非常積極,我只是在做一些愚蠢的事情,或者做得不正確。
究竟是什麼你想達到什麼效果? – ChrisF
我希望當用戶激活它時,我可以將此工具欄動畫顯示到屏幕上。 所以當他們點擊一個按鈕時,工具欄會從窗口底部滑到屏幕上(當他們點擊不同的按鈕,不同的工具欄顯示等等)。 –