从另一个用户控件的样式动画UserControl

时间:2016-02-03 16:34:43

标签: wpf xaml animation storyboard controltemplate

我已经实现了一个切换按钮,并根据它是打开还是关闭,我想为另一个控件设置动画。看来import tkinter as tk def callback(): print("Hello World") root = tk.Tk() menu = tk.Menu(root) # Adding cascade menu2 = tk.Menu(menu, tearoff=0) menu2.add_command(label="CascadeItem", command=callback) menu.add_cascade(menu=menu2, label="Cascade") # Adding non-cascade menu.add_command(label="NonCascade", command=callback) root.config(menu=menu) root.mainloop() 内的TargetName是不允许的,我怎么能解决这个难题?

  

错误行:Storyboard.TargetName =" grdEditBookmark"

ControlTemplate

1 个答案:

答案 0 :(得分:1)

我已经用Chris W.的建议实现了预期的行为。这是片段:

           <Border Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" x:Name="grdEditBookmark" BorderBrush="Gray" CornerRadius="2" VerticalAlignment="Top"  Margin="5,0" BorderThickness="1">
                <Border.Style>
                    <Style TargetType="Border">
                        <Setter Property="Height" Value="0"></Setter>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ElementName=toggleButton, Path=IsChecked}" Value="True">
                                <DataTrigger.EnterActions>
                                    <BeginStoryboard Storyboard="{StaticResource sbGrdEditBookmarkShow}"></BeginStoryboard>
                                </DataTrigger.EnterActions>
                                <DataTrigger.ExitActions>
                                    <BeginStoryboard Storyboard="{StaticResource sbGrdEditBookmarkHide}"></BeginStoryboard>
                                </DataTrigger.ExitActions>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Border.Style>
            </Border>