这是我的代码:
<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>