Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 故事板只运行一次_C#_Wpf_Xaml - Fatal编程技术网

C# 故事板只运行一次

C# 故事板只运行一次,c#,wpf,xaml,C#,Wpf,Xaml,这是我的代码: <Style TargetType="ContentControl" x:Key="MenuItemsStyle"> <Setter Property="Background" Value="Transparent"/> <Setter Property="Template"> <Setter.Value>

这是我的代码:

  <Style  TargetType="ContentControl" x:Key="MenuItemsStyle">
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                          <Border Name="mainBorder" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                                        <Border.Style>
                                            <Style TargetType="Border">
                                                <Setter Property="BorderThickness" Value="1.2"/>
                                                <Setter Property="Background" >
                                                    <Setter.Value>
                                                        <SolidColorBrush Color="Transparent"/>
                                                    </Setter.Value>
                                                </Setter>
                                                <Setter Property="BorderBrush" >
                                                    <Setter.Value>
                                                        <SolidColorBrush Color="Transparent"/>
                                                    </Setter.Value>
                                                </Setter>
                                                <Style.Triggers>
                                                    <EventTrigger RoutedEvent="Border.MouseEnter">
                                                        <BeginStoryboard Storyboard="{StaticResource BorderEnterStoryBoard}"/>
                                                    </EventTrigger>
                                                    <EventTrigger RoutedEvent="Border.MouseLeave">
                                                        <BeginStoryboard Storyboard="{StaticResource BorderLeaveStoryBoard}"/>
                                                    </EventTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Border.Style>
                                        <ContentPresenter VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                                                          Content="{TemplateBinding ContentControl.Content}">
                                            <ContentPresenter.Triggers>
                                                <EventTrigger RoutedEvent="ContentPresenter.MouseDown">
                                                    <BeginStoryboard Storyboard="{StaticResource ViewPort3DStoryBoard}"/>
                                                </EventTrigger>
                                            </ContentPresenter.Triggers>
                                        </ContentPresenter>
                                    </Border>
                         </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <EventTrigger RoutedEvent="ContentControl.MouseDown">
                        <BeginStoryboard Storyboard="{StaticResource ContentControlStoryBoard}"/>
                    </EventTrigger>
                </Style.Triggers>
            </Style>

如您所见,我在窗口资源中创建了4个情节提要,然后将它们用于样式和模板

1.如何运行情节提要?在用户单击内容控件后,内容控件填充窗口空间,现在我希望动画(情节提要)在用户再次单击内容控件时不要再次运行。(我希望停止所有情节提要均为边框样式、模板和内容控件样式) 2.我如何才能做得更好(我的意思是使用1或2个故事板并调用它们一次,例如在内容的鼠标下键时调用全部)

编辑: 故事板如下:

<Window.Resources>

        <Storyboard Name="ViewPort3DStoryBoard" x:Key="ViewPort3DStoryBoard">
            <DoubleAnimation Storyboard.TargetName="aar3D" Storyboard.TargetProperty="Angle" From="0" To="90" Duration="0:0:0.2"/>
            <DoubleAnimation Storyboard.TargetName="aar3D" Storyboard.TargetProperty="Angle" From="-90" To="0" Duration="0:0:0.25" BeginTime="0:0:0.2"/>
        </Storyboard >
        <Storyboard Name="ContentControlStoryBoard" x:Key="ContentControlStoryBoard">
            <DoubleAnimation Storyboard.TargetProperty="(ContentControl.Width)" To="{x:Static SystemParameters.PrimaryScreenWidth}" Duration="0:0:0.45" BeginTime="0:0:0"/>
            <DoubleAnimation Storyboard.TargetProperty="(ContentControl.Height)" To="{x:Static SystemParameters.PrimaryScreenHeight}" Duration="0:0:0.45" BeginTime="0:0:0"/>
            <ThicknessAnimation To="0" Storyboard.TargetProperty="(ContentControl.Margin)" Duration="0:0:0.25" BeginTime="0:0:0"/>
            <DoubleAnimation To="0" Storyboard.TargetProperty="(Canvas.Top)" Duration="0:0:0.25" BeginTime="0:0:0"/>
            <DoubleAnimation To="0" Storyboard.TargetProperty="(Canvas.Left)" Duration="0:0:0.25" BeginTime="0:0:0"/>
        </Storyboard>
        <Storyboard Name="BorderEnterStoryBoard" x:Key="BorderEnterStoryBoard">
            <ColorAnimation From="Transparent" To="#FF007ACC" Duration="0:0:0.1" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)"/>
            <ColorAnimation From="Transparent" To="#26FFFFFF" Duration="0:0:0.1" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"/>
        </Storyboard>
        <Storyboard Name="BorderLeaveStoryBoard" x:Key="BorderLeaveStoryBoard">
            <ColorAnimation From="#FF007ACC" To="Transparent" Duration="0:0:0.3" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)"/>
            <ColorAnimation From="#26FFFFFF" To="Transparent" Duration="0:0:0.3" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"/>
        </Storyboard>
</Window.Resources>

VB

C#


Fillbeavior Stop应该可以做到这一点

   Dim s As New Storyboard
   s = CType(FindResource("YourStoryBoardName"), Storyboard)
   s.Begin()
    Storyboard s 
    s = this.FindResource("YourStoryBoardName") as Storyboard;
    s.Begin();