這是我的代碼:故事板只運行一次
<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. 我該如何運行故事板一次?用戶點擊內容控件後,內容控件填充窗口空間現在我想要動畫(storyboard)再次運行,如果用戶再次點擊內容控件(我想要停止所有storyboard中的邊框風格,模板和內容控件風格) 我2.how可以做得更好(我的意思是使用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>