• WPF 右键菜单动画


    颜色样式:

    1 <LinearGradientBrush x:Key="MenuPopupBrush"
    2 EndPoint="0.5,1"
    3 StartPoint="0.5,0">
    4 <GradientStop Color="#7FFFFFFF"
    5 Offset="0" />
    6 <GradientStop Color="#C28B008B"
    7 Offset="0.3"/>
    8 <GradientStop Color="#FF4B0082"
    9 Offset="1" />
    10  </LinearGradientBrush>

    菜单样式:

    1 <Style x:Key="MyContextMenu" TargetType="{x:Type ContextMenu}">
    2 <Setter Property="Template">
    3 <Setter.Value>
    4 <ControlTemplate TargetType="{x:Type ContextMenu}">
    5 <Border x:Name="Border" CornerRadius="4"
    6 Background="{StaticResource MenuPopupBrush}"
    7 BorderThickness="1">
    8 <Border.BorderBrush>
    9 <SolidColorBrush Color="#FF888888" />
    10 </Border.BorderBrush>
    11 <StackPanel IsItemsHost="True"
    12 KeyboardNavigation.DirectionalNavigation="Cycle" />
    13
    14 </Border>
    15 <ControlTemplate.Triggers>
    16 <MultiTrigger>
    17 <MultiTrigger.Conditions>
    18 <Condition Property="IsMouseOver" Value="True"/>
    19 </MultiTrigger.Conditions>
    20 <MultiTrigger.EnterActions>
    21 <BeginStoryboard>
    22 <Storyboard>
    23 <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(FrameworkElement.Width)">
    24 <SplineDoubleKeyFrame KeyTime="00:00:00.0020000" Value="0"/>
    25 <SplineDoubleKeyFrame KeyTime="00:00:00.2520000" Value="142"/>
    26 <SplineDoubleKeyFrame KeyTime="00:00:00.3450000" Value="120"/>
    27 <SplineDoubleKeyFrame KeyTime="00:00:00.4300000" Value="142"/>
    28 </DoubleAnimationUsingKeyFrames>
    29 <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(FrameworkElement.Height)">
    30 <SplineDoubleKeyFrame KeyTime="00:00:00.0020000" Value="0"/>
    31 <SplineDoubleKeyFrame KeyTime="00:00:00.2520000" Value="200"/>
    32 <SplineDoubleKeyFrame KeyTime="00:00:00.3450000" Value="170"/>
    33 <SplineDoubleKeyFrame KeyTime="00:00:00.4300000" Value="200"/>
    34 </DoubleAnimationUsingKeyFrames>
    35 </Storyboard>
    36 </BeginStoryboard>
    37 </MultiTrigger.EnterActions>
    38 </MultiTrigger>
    39 </ControlTemplate.Triggers>
    40 </ControlTemplate>
    41 </Setter.Value>
    42 </Setter>
    43 </Style>

    右键菜单:

    1 <ContextMenu Style="{StaticResource MyContextMenu}">
    2 <MenuItem Header="测试二次"/>
    3 <MenuItem Header="测试三次">
    4 <MenuItem.Icon>
    5 <Image Source="Add.png" Width="12" Height="12"/>
    6 </MenuItem.Icon>
    7 </MenuItem>
    8 <Separator Opacity="0.4"></Separator>
    9 <MenuItem Header="测试四次"/>
    10 <MenuItem Header="测试五次"/>
    11 <MenuItem Header="测试六次"/>
    12 <Separator Opacity="0.4" ></Separator>
    13 <MenuItem Header="测试二次"/>
    14 <MenuItem Header="测试三次"/>
    15 <MenuItem Header="测试五次"/>
    16 <Separator Opacity="0.4"></Separator>
    17 <MenuItem Header="测试六次">
    18 <MenuItem.Icon>
    19 <Image Source="Delete.png" Width="12" Height="12"/>
    20 </MenuItem.Icon>
    21 </MenuItem>
    22  </ContextMenu>
  • 相关阅读:
    KVM安装以及远程连接
    开博客祭
    CQOI 2021
    琐记——学长们
    大事祭
    关于洛谷与博客园的博客的一些声明
    CSP-S 2020 & NOIP 2020 日记与游记
    调和级数
    快速乘
    二叉堆
  • 原文地址:https://www.cnblogs.com/midcn/p/2006629.html
Copyright © 2020-2023  润新知