精华内容
下载资源
问答
  • 默认的MenuItem样式比较普通,这次自定义MenuItem的样式也只是对MenuItem的颜色风格进行变化。需要其他功能的变化,大家可以根据样式代码进行扩展。 MenuItem的样式代码: <!--MenuItem--> <Style Target...
  • 主要介绍了Android MenuItem 自定义长按事件的实现,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
  • WPF中MenuItem原生样式

    2016-07-22 06:27:09
    WPF中MenuItem原生样式
  • 经典wpf菜单MenuItem样式1

    千次下载 热门讨论 2015-05-06 04:20:35
    wpf菜单MenuItem样式经典源代码,绝对经典,颜色根据自己需要修改
  • 博文链接:https://daniel-wuz.iteye.com/blog/209524
  • WPF:MenuItem样式

    千次阅读 2019-10-02 18:05:09
    基础信息 ...1、MenuItem 样式 <Window.Resources> <Style TargetType="{x:Type MenuItem}"> <!--<Setter Property="Background" Value="#999999" />--> ...

     

    基础信息

    1、MenuItem 样式

        <Window.Resources>
    
            <Style TargetType="{x:Type MenuItem}">
                <!--<Setter Property="Background" Value="#999999" />-->
                <!--<Setter Property="Foreground" Value="#999999" />-->
                <!--MenuItem文字颜色和menu的文字颜色一样-->
                <!--<Setter Property="Foreground" Value="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Menu}}}"/>-->
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type MenuItem}">
                            <Border x:Name="Border"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <!--<ColumnDefinition x:Name="Col0" SharedSizeGroup="MenuItemIconColumnGroup" MinWidth="17" Width="Auto"/>-->
                                        <ColumnDefinition Width="Auto"  SharedSizeGroup="MenuTextColumnGroup"/>
                                        <!--<ColumnDefinition Width="Auto"  SharedSizeGroup="MenuItemIGTColumnGroup"/>-->
                                        <!--<ColumnDefinition x:Name="Col3" Width="14"/>-->
                                    </Grid.ColumnDefinitions>
    
                                    <!-- ContentPresenter to show an Icon if needed -->
                                    <ContentPresenter Grid.Column="0" 
                                                      Margin="4,0,6,0" x:Name="Icon" 
                                                      VerticalAlignment="Center" ContentSource="Icon"/>
    
                                    <!-- Glyph is a checkmark if needed for a checkable menu -->
                                    <Grid Grid.Column="0" Visibility="Hidden" Margin="4,0,6,0" x:Name="GlyphPanel" VerticalAlignment="Center">
                                        <Path x:Name="GlyphPanelpath" VerticalAlignment="Center" Fill="{TemplateBinding Foreground}" 
                                              Data="M0,2 L0,4.8 L2.5,7.4 L7.1,2.8 L7.1,0 L2.5,4.6 z" FlowDirection="LeftToRight"/>
                                    </Grid>
    
                                    <!-- Content for the menu text etc -->
                                    <ContentPresenter Grid.Column="1"
                                              Margin="{TemplateBinding Padding}"
                                              x:Name="HeaderHost"
                                              RecognizesAccessKey="True"
                                              VerticalAlignment="Center"
                                              ContentSource="Header"/>
    
                                    <!-- Content for the menu IGT -->
                                    <ContentPresenter Grid.Column="2"
                                              Margin="8,1,8,1"
                                              x:Name="IGTHost"
                                              ContentSource="InputGestureText"
                                              VerticalAlignment="Center"/>
    
                                    <!-- Arrow drawn path which points to the next level of the menu -->
                                    <Grid Grid.Column="3" Margin="4,0,6,0" x:Name="ArrowPanel" VerticalAlignment="Center">
                                        <Path x:Name="ArrowPanelPath" HorizontalAlignment="Right" VerticalAlignment="Center" 
                                              Fill="{TemplateBinding Foreground}" Data="M0,0 L0,8 L4,4 z"/>
                                    </Grid>
    
                                    <!-- The Popup is the body of the menu which expands 
                                         down or across depending on the level of the item -->
                                    <Popup IsOpen="{Binding Path=IsSubmenuOpen, 
                                           RelativeSource ={RelativeSource TemplatedParent}}" 
                                           Placement="Right" x:Name="SubMenuPopup" Focusable="false" 
                                           PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}">
                                        <Border x:Name="SubMenuBorder" BorderBrush="{Binding Path=Foreground, 
                                            RelativeSource={RelativeSource AncestorType={x:Type Menu}}}" 
                                            BorderThickness="1" Padding="2,2,2,2">
                                            <Grid x:Name="SubMenu" Grid.IsSharedSizeScope="True">
                                                <!-- StackPanel holds children of the menu. This is set by IsItemsHost=True  KeyboardNavigationMode = "Cycle" -->
                                                <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"/>   
                                            </Grid>
                                        </Border>
                                    </Popup>
                                </Grid>
                            </Border>
    
                            <!-- These triggers re-configure the four arrangements 
                                 of MenuItem to show different levels of menu via Role -->
                            <ControlTemplate.Triggers>
                                <!-- Role = TopLevelHeader : this is the root menu item in a menu; the Popup expands down -->
                                <Trigger Property="Role" Value="TopLevelHeader">
                                    <Setter Property="Padding" Value="6,1,6,1"/>
                                    <Setter Property="Placement" Value="Left" TargetName="SubMenuPopup"/>
                                    <!--<Setter Property="MinWidth" Value="0" TargetName="Col0"/>-->
                                    <!--<Setter Property="Width" Value="Auto" TargetName="Col3"/>-->
                                    <Setter Property="CornerRadius" Value="5,5,0,0" TargetName="Border"/>
                                    <Setter Property="Visibility" Value="Collapsed" TargetName="Icon"/>
                                    <Setter Property="Visibility" Value="Collapsed" TargetName="GlyphPanel"/>
                                    <Setter Property="Visibility" Value="Collapsed" TargetName="IGTHost"/>
                                    <Setter Property="Visibility" Value="Collapsed" TargetName="ArrowPanel"/>
                                </Trigger>
    
                                <!-- Role = TopLevelItem :  this is a child menu item from the top level without any child items-->
                                <Trigger Property="Role" Value="TopLevelItem">
                                    <Setter Property="Padding" Value="6,1,6,1"/>
                                    <Setter Property="Visibility" Value="Collapsed" TargetName="ArrowPanel"/>
                                </Trigger>
    
                                <!-- Role = SubMenuHeader : this is a child menu item which does not have children -->
                                <Trigger Property="Role" Value="SubmenuHeader">
                                    <Setter Property="DockPanel.Dock" Value="Top"/>
                                    <Setter Property="Padding" Value="0,2,0,2"/>
                                </Trigger>
    
                                <!-- Role = SubMenuItem : this is a child menu item which has children-->
                                <Trigger Property="Role" Value="SubmenuItem">
                                    <Setter Property="DockPanel.Dock" Value="Top"/>
                                    <Setter Property="Padding" Value="0,2,0,2"/>
                                    <Setter Property="Visibility" Value="Collapsed" TargetName="ArrowPanel"/>
                                </Trigger>
                                <Trigger Property="IsSuspendingPopupAnimation" Value="true">
                                    <Setter Property="PopupAnimation" Value="None" TargetName="SubMenuPopup"/>
                                </Trigger>
    
                                <!-- If no Icon is present the we collapse the Icon Content -->
                                <Trigger Property="Icon" Value="{x:Null}">
                                    <Setter Property="Visibility" Value="Collapsed" TargetName="Icon"/>
                                </Trigger>
    
                                <!-- The GlyphPanel contains the CheckMark -->
                                <Trigger Property="IsChecked" Value="true">
                                    <Setter Property="Visibility" Value="Visible" TargetName="GlyphPanel"/>
                                    <Setter Property="Visibility" Value="Collapsed" TargetName="Icon"/>
                                </Trigger>
    
                                <!-- Using the system colors for the Menu Highlight and IsEnabled-->
                                <Trigger Property="IsHighlighted" Value="true">
                                    <Setter Property="Background" Value="#ff0000" TargetName="Border"/>
                                    <Setter Property="Foreground" Value="#0036ff"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="false">
                                    <Setter Property="Foreground" Value="#ff0000"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    
            <!--工具数据源-->
            <XmlDataProvider x:Key="toolsDS" Source="Config\Tools\Tools.xml" XPath="Tools/Tool"></XmlDataProvider>
            <!--Tool模板-->
            <HierarchicalDataTemplate DataType="Tool" ItemsSource="{Binding XPath=Tool}" >
                <StackPanel Orientation="Horizontal">
                    <TextBlock Tag ="{Binding XPath=@Name}" Width="38">
                        <Image Source="{Binding XPath=@ImagePath}" Width="38" Height="38"></Image>
                    </TextBlock>
                </StackPanel>
            </HierarchicalDataTemplate>
            
            
            
        </Window.Resources>
        
        
    View Code

    2、Menu、MenuItem、 直接拷贝就可查看示例

        <Window.Resources>
    
            <!--Control colors.-->
            <Color x:Key="WindowColor">#FFE8EDF9</Color>
            <Color x:Key="ContentAreaColorLight">#FFC5CBF9</Color>
            <Color x:Key="ContentAreaColorDark">#FF7381F9</Color>
    
            <Color x:Key="DisabledControlLightColor">#FFE8EDF9</Color>
            <Color x:Key="DisabledControlDarkColor">#FFC5CBF9</Color>
            <Color x:Key="DisabledForegroundColor">#FF888888</Color>
    
            <Color x:Key="SelectedBackgroundColor">#FFC5CBF9</Color>
            <Color x:Key="SelectedUnfocusedColor">#FFDDDDDD</Color>
    
            <Color x:Key="ControlLightColor">White</Color>
            <Color x:Key="ControlMediumColor">#FF7381F9</Color>
            <Color x:Key="ControlDarkColor">#FF211AA9</Color>
    
            <Color x:Key="ControlMouseOverColor">#FF3843C4</Color>
            <Color x:Key="ControlPressedColor">#FF211AA9</Color>
    
    
            <Color x:Key="GlyphColor">#FF444444</Color>
            <Color x:Key="GlyphMouseOver">sc#1, 0.004391443, 0.002428215, 0.242281124</Color>
    
            <!--Border colors-->
            <Color x:Key="BorderLightColor">#FFCCCCCC</Color>
            <Color x:Key="BorderMediumColor">#FF888888</Color>
            <Color x:Key="BorderDarkColor">#FF444444</Color>
    
            <Color x:Key="PressedBorderLightColor">#FF888888</Color>
            <Color x:Key="PressedBorderDarkColor">#FF444444</Color>
    
            <Color x:Key="DisabledBorderLightColor">#FFAAAAAA</Color>
            <Color x:Key="DisabledBorderDarkColor">#FF888888</Color>
    
            <Color x:Key="DefaultBorderBrushDarkColor">Black</Color>
    
            <!--Control-specific resources.-->
            <Color x:Key="HeaderTopColor">#FFC5CBF9</Color>
            <Color x:Key="DatagridCurrentCellBorderColor">Black</Color>
            <Color x:Key="SliderTrackDarkColor">#FFC5CBF9</Color>
    
            <Color x:Key="NavButtonFrameColor">#FF3843C4</Color>
    
            <LinearGradientBrush x:Key="MenuPopupBrush"
                         EndPoint="0.5,1"
                         StartPoint="0.5,0">
                <GradientStop Color="{DynamicResource ControlLightColor}"
                    Offset="0" />
                <GradientStop Color="{DynamicResource ControlMediumColor}"
                    Offset="0.5" />
                <GradientStop Color="{DynamicResource ControlLightColor}"
                    Offset="1" />
            </LinearGradientBrush>
    
            <LinearGradientBrush x:Key="ProgressBarIndicatorAnimatedFill"
                         StartPoint="0,0"
                         EndPoint="1,0">
                <LinearGradientBrush.GradientStops>
                    <GradientStopCollection>
                        <GradientStop Color="#000000FF"
                        Offset="0" />
                        <GradientStop Color="#600000FF"
                        Offset="0.4" />
                        <GradientStop Color="#600000FF"
                        Offset="0.6" />
                        <GradientStop Color="#000000FF"
                        Offset="1" />
                    </GradientStopCollection>
                </LinearGradientBrush.GradientStops>
            </LinearGradientBrush>
    
    
            <Style x:Key="{x:Type Menu}"
           TargetType="{x:Type Menu}">
                <Setter Property="OverridesDefaultStyle"
              Value="True" />
                <Setter Property="SnapsToDevicePixels"
              Value="True" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Menu}">
                            <Border BorderThickness="1">
                                <Border.BorderBrush>
                                    <LinearGradientBrush StartPoint="0,0"
                                     EndPoint="0,1">
                                        <LinearGradientBrush.GradientStops>
                                            <GradientStopCollection>
                                                <GradientStop Color="{DynamicResource BorderLightColor}"
                                    Offset="0.0" />
                                                <GradientStop Color="{DynamicResource BorderDarkColor}"
                                    Offset="1.0" />
                                            </GradientStopCollection>
                                        </LinearGradientBrush.GradientStops>
                                    </LinearGradientBrush>
    
                                </Border.BorderBrush>
                                <Border.Background>
                                    <LinearGradientBrush EndPoint="0.5,1"
                                     StartPoint="0.5,0">
                                        <GradientStop Color="{DynamicResource ControlLightColor}"
                                Offset="0" />
                                        <GradientStop Color="{DynamicResource ControlMediumColor}"
                                Offset="1" />
                                    </LinearGradientBrush>
                                </Border.Background>
                                <StackPanel ClipToBounds="True"
                          Orientation="Horizontal"
                          IsItemsHost="True" />
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    
            
            
            
           <Style x:Key="{x:Static MenuItem.SeparatorStyleKey}"
           TargetType="{x:Type Separator}">
      <Setter Property="Height"
              Value="1" />
      <Setter Property="Margin"
              Value="0,4,0,4" />
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type Separator}">
            <Border BorderThickness="1">
              <Border.BorderBrush>
                <SolidColorBrush Color="{DynamicResource BorderMediumColor}" />
              </Border.BorderBrush>
            </Border>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
    
    
            <!--ScrollViewer for a MenuItem-->
            <MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter" />
    
            <Style x:Key="MenuScrollViewer"
           TargetType="{x:Type ScrollViewer}"
           BasedOn="{x:Null}">
                <Setter Property="HorizontalScrollBarVisibility"
              Value="Hidden" />
                <Setter Property="VerticalScrollBarVisibility"
              Value="Auto" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ScrollViewer}">
                            <Grid SnapsToDevicePixels="True">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Border Grid.Row="1"
                      Grid.Column="0">
                                    <ScrollContentPresenter Margin="{TemplateBinding Padding}" />
                                </Border>
    
                                <!--Style="{StaticResource MenuScrollButton}"-->
                                <RepeatButton 
                            Grid.Row="0"
                            Grid.Column="0"
                            Command="{x:Static ScrollBar.LineUpCommand}"
                            CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                            Focusable="False">
                                    <RepeatButton.Visibility>
                                        <MultiBinding FallbackValue="Visibility.Collapsed"
                                Converter="{StaticResource MenuScrollingVisibilityConverter}"
                                ConverterParameter="0">
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}"
                             Path="ComputedVerticalScrollBarVisibility" />
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}"
                             Path="VerticalOffset" />
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}"
                             Path="ExtentHeight" />
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}"
                             Path="ViewportHeight" />
                                        </MultiBinding>
                                    </RepeatButton.Visibility>
                                    <!--<Path Fill="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}"
                      Data="{StaticResource UpArrow}" />-->
                                </RepeatButton>
                                
                                <!--Style="{StaticResource MenuScrollButton}"-->
                                <RepeatButton 
                            Grid.Row="2"
                            Grid.Column="0"
                            Command="{x:Static ScrollBar.LineDownCommand}"
                            CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                            Focusable="False">
                                    <RepeatButton.Visibility>
                                        <MultiBinding FallbackValue="Visibility.Collapsed"
                                Converter="{StaticResource MenuScrollingVisibilityConverter}"
                                ConverterParameter="100">
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}"
                             Path="ComputedVerticalScrollBarVisibility" />
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}"
                             Path="VerticalOffset" />
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}"
                             Path="ExtentHeight" />
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}"
                             Path="ViewportHeight" />
                                        </MultiBinding>
                                    </RepeatButton.Visibility>
                                    <Path Fill="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}"
                       />
                                    <!--Data="{StaticResource DownArrow}"-->
                                </RepeatButton>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    
    
    
            <!-- TopLevelHeader -->
    <ControlTemplate x:Key="{x:Static MenuItem.TopLevelHeaderTemplateKey}"
                     TargetType="{x:Type MenuItem}">
      <Border x:Name="Border">
        <Grid>
          <ContentPresenter Margin="6,3,6,3"
                            ContentSource="Header"
                            RecognizesAccessKey="True" />
          <Popup x:Name="Popup"
                 Placement="Bottom"
                 IsOpen="{TemplateBinding IsSubmenuOpen}"
                 AllowsTransparency="True"
                 Focusable="False"
                 PopupAnimation="Fade">
            <Border x:Name="SubmenuBorder"
                    SnapsToDevicePixels="True"
                    BorderThickness="1"
                    Background="{DynamicResource MenuPopupBrush}">
              <Border.BorderBrush>
                <SolidColorBrush Color="{DynamicResource BorderMediumColor}" />
              </Border.BorderBrush>
              <ScrollViewer CanContentScroll="True"
                            Style="{StaticResource MenuScrollViewer}">
                <StackPanel IsItemsHost="True"
                            KeyboardNavigation.DirectionalNavigation="Cycle" />
              </ScrollViewer>
            </Border>
          </Popup>
        </Grid>
      </Border>
      <ControlTemplate.Triggers>
        <Trigger Property="IsSuspendingPopupAnimation"
                 Value="true">
          <Setter TargetName="Popup"
                  Property="PopupAnimation"
                  Value="None" />
        </Trigger>
        <Trigger Property="IsHighlighted"
                 Value="true">
          <Setter TargetName="Border"
                  Property="BorderBrush"
                  Value="Transparent" />
          <Setter Property="Background"
                  TargetName="Border">
            <Setter.Value>
              <LinearGradientBrush StartPoint="0,0"
                                   EndPoint="0,1">
                <LinearGradientBrush.GradientStops>
                  <GradientStopCollection>
                    <GradientStop Color="{StaticResource ControlLightColor}" />
                    <GradientStop Color="{StaticResource ControlMouseOverColor}"
                                  Offset="1.0" />
                  </GradientStopCollection>
                </LinearGradientBrush.GradientStops>
              </LinearGradientBrush>
    
            </Setter.Value>
          </Setter>
        </Trigger>
        <Trigger SourceName="Popup"
                 Property="AllowsTransparency"
                 Value="True">
          <Setter TargetName="SubmenuBorder"
                  Property="CornerRadius"
                  Value="0,0,4,4" />
          <Setter TargetName="SubmenuBorder"
                  Property="Padding"
                  Value="0,0,0,3" />
        </Trigger>
        <Trigger Property="IsEnabled"
                 Value="False">
          <Setter Property="Foreground">
            <Setter.Value>
              <SolidColorBrush Color="{StaticResource DisabledForegroundColor}" />
            </Setter.Value>
          </Setter>
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>
    
    <!-- TopLevelItem -->
    <ControlTemplate x:Key="{x:Static MenuItem.TopLevelItemTemplateKey}"
                     TargetType="{x:Type MenuItem}">
      <Border x:Name="Border">
        <Grid>
          <ContentPresenter Margin="6,3,6,3"
                            ContentSource="Header"
                            RecognizesAccessKey="True" />
        </Grid>
      </Border>
      <ControlTemplate.Triggers>
        <Trigger Property="IsHighlighted"
                 Value="true">
          <Setter Property="Background"
                  TargetName="Border">
            <Setter.Value>
              <LinearGradientBrush StartPoint="0,0"
                                   EndPoint="0,1">
                <LinearGradientBrush.GradientStops>
                  <GradientStopCollection>
                    <GradientStop Color="{StaticResource ControlLightColor}" />
                    <GradientStop Color="{StaticResource ControlMouseOverColor}"
                                  Offset="1.0" />
                  </GradientStopCollection>
                </LinearGradientBrush.GradientStops>
              </LinearGradientBrush>
    
            </Setter.Value>
          </Setter>
        </Trigger>
        <Trigger Property="IsEnabled"
                 Value="False">
          <Setter Property="Foreground">
            <Setter.Value>
              <SolidColorBrush Color="{StaticResource DisabledForegroundColor}" />
            </Setter.Value>
          </Setter>
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>
    
    <!-- SubmenuItem -->
    <ControlTemplate x:Key="{x:Static MenuItem.SubmenuItemTemplateKey}"
                     TargetType="{x:Type MenuItem}">
      <Border x:Name="Border"
              BorderThickness="1">
        <Grid>
          <Grid.ColumnDefinitions>
            <!--<ColumnDefinition Width="Auto"
                              SharedSizeGroup="Icon" />-->
            <ColumnDefinition Width="*" />
            <!--<ColumnDefinition Width="Auto"
                              SharedSizeGroup="Shortcut" />
            <ColumnDefinition Width="13" />-->
          </Grid.ColumnDefinitions>
          <ContentPresenter x:Name="Icon"
                            Margin="6,0,6,0"
                            VerticalAlignment="Center"
                            ContentSource="Icon" />
          <Border x:Name="Check"
                  Width="13"
                  Height="13"
                  Visibility="Collapsed"
                  Margin="6,0,6,0"
                  BorderThickness="1">
            <Border.BorderBrush>
              <LinearGradientBrush StartPoint="0,0"
                                   EndPoint="0,1">
                <LinearGradientBrush.GradientStops>
                  <GradientStopCollection>
                    <GradientStop Color="{DynamicResource BorderLightColor}"
                                  Offset="0.0" />
                    <GradientStop Color="{DynamicResource BorderDarkColor}"
                                  Offset="1.0" />
                  </GradientStopCollection>
                </LinearGradientBrush.GradientStops>
              </LinearGradientBrush>
    
            </Border.BorderBrush>
            <Border.Background>
              <LinearGradientBrush StartPoint="0,0"
                                   EndPoint="0,1">
                <LinearGradientBrush.GradientStops>
                  <GradientStopCollection>
                    <GradientStop Color="{DynamicResource ControlLightColor}" />
                    <GradientStop Color="{DynamicResource ControlMediumColor}"
                                  Offset="1.0" />
                  </GradientStopCollection>
                </LinearGradientBrush.GradientStops>
              </LinearGradientBrush>
            </Border.Background>
            <Path x:Name="CheckMark"
                  Width="7"
                  Height="7"
                  Visibility="Hidden"
                  SnapsToDevicePixels="False"
                  StrokeThickness="2"
                  Data="M 0 0 L 7 7 M 0 7 L 7 0">
              <Path.Stroke>
                <SolidColorBrush Color="{DynamicResource GlyphColor}" />
              </Path.Stroke>
            </Path>
          </Border>
          <ContentPresenter x:Name="HeaderHost"
                            Grid.Column="1"
                            ContentSource="Header"
                            RecognizesAccessKey="True" />
          <TextBlock x:Name="InputGestureText"
                     Grid.Column="2"
                     Text="{TemplateBinding InputGestureText}"
                     Margin="5,2,0,2"
                     DockPanel.Dock="Right" />
        </Grid>
      </Border>
      <ControlTemplate.Triggers>
        <Trigger Property="ButtonBase.Command"
                 Value="{x:Null}" />
        <Trigger Property="Icon"
                 Value="{x:Null}">
          <Setter TargetName="Icon"
                  Property="Visibility"
                  Value="Hidden" />
        </Trigger>
        <Trigger Property="IsChecked"
                 Value="true">
          <Setter TargetName="CheckMark"
                  Property="Visibility"
                  Value="Visible" />
        </Trigger>
        <Trigger Property="IsCheckable"
                 Value="true">
          <Setter TargetName="Check"
                  Property="Visibility"
                  Value="Visible" />
          <Setter TargetName="Icon"
                  Property="Visibility"
                  Value="Hidden" />
        </Trigger>
        <Trigger Property="IsHighlighted"
                 Value="true">
          <Setter Property="Background"
                  TargetName="Border">
            <Setter.Value>
              <LinearGradientBrush EndPoint="0.5,1"
                                   StartPoint="0.5,0">
                <GradientStop Color="Transparent"
                              Offset="0" />
                <GradientStop Color="{DynamicResource ControlMouseOverColor}"
                              Offset="1" />
              </LinearGradientBrush>
            </Setter.Value>
          </Setter>
          <Setter Property="BorderBrush"
                  TargetName="Border">
            <Setter.Value>
              <LinearGradientBrush EndPoint="0.5,1"
                                   StartPoint="0.5,0">
                <GradientStop Color="{DynamicResource BorderMediumColor}"
                              Offset="0" />
                <GradientStop Color="Transparent"
                              Offset="1" />
              </LinearGradientBrush>
            </Setter.Value>
          </Setter>
        </Trigger>
        <Trigger Property="IsEnabled"
                 Value="false">
          <Setter Property="Foreground">
            <Setter.Value>
              <SolidColorBrush Color="{StaticResource DisabledForegroundColor}" />
            </Setter.Value>
          </Setter>
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>
    
    <ControlTemplate x:Key="{x:Static MenuItem.SubmenuHeaderTemplateKey}"
                     TargetType="{x:Type MenuItem}">
      <Border x:Name="Border"
              BorderThickness="1">
        <Grid>
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"
                              SharedSizeGroup="Icon" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto"
                              SharedSizeGroup="Shortcut" />
            <ColumnDefinition Width="13" />
          </Grid.ColumnDefinitions>
          <ContentPresenter x:Name="Icon"
                            Margin="6,0,6,0"
                            VerticalAlignment="Center"
                            ContentSource="Icon" />
          <ContentPresenter x:Name="HeaderHost"
                            Grid.Column="1"
                            ContentSource="Header"
                            RecognizesAccessKey="True" />
          <TextBlock x:Name="InputGestureText"
                     Grid.Column="2"
                     Text="{TemplateBinding InputGestureText}"
                     Margin="5,2,2,2"
                     DockPanel.Dock="Right" />
          <Path Grid.Column="3"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Data="M 0 0 L 0 7 L 4 3.5 Z">
            <Path.Fill>
              <SolidColorBrush Color="{DynamicResource GlyphColor}" />
            </Path.Fill>
          </Path>
          <Popup x:Name="Popup"
                 Placement="Right"
                 HorizontalOffset="-4"
                 IsOpen="{TemplateBinding IsSubmenuOpen}"
                 AllowsTransparency="True"
                 Focusable="False"
                 PopupAnimation="Fade">
            <Border x:Name="SubmenuBorder"
                    SnapsToDevicePixels="True"
                    Background="{DynamicResource MenuPopupBrush}"
                    BorderThickness="1">
              <Border.BorderBrush>
                <SolidColorBrush Color="{DynamicResource BorderMediumColor}" />
              </Border.BorderBrush>
              <ScrollViewer CanContentScroll="True"
                            Style="{StaticResource MenuScrollViewer}">
                <StackPanel IsItemsHost="True"
                            KeyboardNavigation.DirectionalNavigation="Cycle" />
              </ScrollViewer>
            </Border>
          </Popup>
        </Grid>
      </Border>
      <ControlTemplate.Triggers>
        <Trigger Property="Icon"
                 Value="{x:Null}">
          <Setter TargetName="Icon"
                  Property="Visibility"
                  Value="Collapsed" />
        </Trigger>
        <Trigger Property="IsHighlighted"
                 Value="true">
          <Setter Property="Background"
                  TargetName="Border">
            <Setter.Value>
              <LinearGradientBrush EndPoint="0.5,1"
                                   StartPoint="0.5,0">
                <GradientStop Color="Transparent"
                              Offset="0" />
                <GradientStop Color="{DynamicResource ControlMouseOverColor}"
                              Offset="1" />
              </LinearGradientBrush>
            </Setter.Value>
          </Setter>
          <Setter Property="BorderBrush"
                  TargetName="Border">
            <Setter.Value>
              <LinearGradientBrush EndPoint="0.5,1"
                                   StartPoint="0.5,0">
                <GradientStop Color="{DynamicResource BorderMediumColor}"
                              Offset="0" />
                <GradientStop Color="Transparent"
                              Offset="1" />
              </LinearGradientBrush>
            </Setter.Value>
          </Setter>
        </Trigger>
        <Trigger SourceName="Popup"
                 Property="AllowsTransparency"
                 Value="True">
          <Setter TargetName="SubmenuBorder"
                  Property="CornerRadius"
                  Value="4" />
          <Setter TargetName="SubmenuBorder"
                  Property="Padding"
                  Value="0,3,0,3" />
        </Trigger>
        <Trigger Property="IsEnabled"
                 Value="false">
          <Setter Property="Foreground">
            <Setter.Value>
              <SolidColorBrush Color="{StaticResource DisabledForegroundColor}" />
            </Setter.Value>
          </Setter>
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>
    
    <!-- MenuItem Style -->
    <Style x:Key="{x:Type MenuItem}"
           TargetType="{x:Type MenuItem}">
      <Setter Property="OverridesDefaultStyle"
              Value="True" />
      <Style.Triggers>
        <Trigger Property="Role"
                 Value="TopLevelHeader">
          <Setter Property="Template"
                  Value="{StaticResource {x:Static MenuItem.TopLevelHeaderTemplateKey}}" />
          <Setter Property="Grid.IsSharedSizeScope"
                  Value="true" />
        </Trigger>
        <Trigger Property="Role"
                 Value="TopLevelItem">
          <Setter Property="Template"
                  Value="{StaticResource {x:Static MenuItem.TopLevelItemTemplateKey}}" />
        </Trigger>
        <Trigger Property="Role"
                 Value="SubmenuHeader">
          <Setter Property="Template"
                  Value="{StaticResource {x:Static MenuItem.SubmenuHeaderTemplateKey}}" />
        </Trigger>
        <Trigger Property="Role"
                 Value="SubmenuItem">
          <Setter Property="Template"
                  Value="{StaticResource {x:Static MenuItem.SubmenuItemTemplateKey}}" />
        </Trigger>
      </Style.Triggers>
    </Style>
    
    
    
    
    
            <XmlDataProvider x:Key="menudata" Source="Config\Tools\MenuData.xml" XPath="MenuData/Operation"></XmlDataProvider>
            <HierarchicalDataTemplate DataType="Operation"
                                      ItemsSource="{Binding XPath=Operation}">
                <StackPanel Orientation="Horizontal" >
                    <TextBlock Text="{Binding XPath=@Name}" HorizontalAlignment="Left"></TextBlock>
                    <TextBlock Text="{Binding XPath=@Gesture}" HorizontalAlignment="Left"></TextBlock>
                </StackPanel>
    
            </HierarchicalDataTemplate>
        </Window.Resources>
    View Code

     

    转载于:https://www.cnblogs.com/shenchao/p/5411742.html

    展开全文
  • MenuItem

    2017-04-11 13:16:10
    MenuItem菜单基本操作 unity 4.6.2 http://www.ceeger.com/Script/ScriptableObject/ScriptableObject.html MenuItem是编辑器类,所以技能导入 using UnityEditor; 命名空间,且一般我们的类也不是集成自...

    MenuItem菜单基本操作unity 4.6.2

    http://www.ceeger.com/Script/ScriptableObject/ScriptableObject.html



    这些菜单分别是:
    • 编辑器顶部的内置菜单(A、B、C、D)

    • 层级视图右键弹出菜单(B)

    • 项目视图右键弹出菜单(A)

    • 检视面板中点击Add Component按钮弹出的菜单(C)

    • 编辑器顶部的新菜单项(E)

    (C) Component菜单下的所有菜单项都是用于为选中的游戏对象添加组件,为了加强该功能,Unity并不允许通过MenuItem向该菜单增加菜单项,而是使用[AddComponentMenu]属性,该属性直接用于自定义的MonoBehaviour类。点击菜单项会自动添加该脚本。
    (E) 如果已有菜单项均不适合自定义工具的功能,也可以自己新建一个菜单项。但Unity并不推荐在多人合作或共享资源的项目中新建菜单项,这可能会导致工具栏异常混乱。

    MenuItem是编辑器类,所以技能导入 using UnityEditor; 命名空间,且一般我们的类也不是集成自MonoBehaviour的,而是集成ScriptableObject

    [MenuItem("MenuItem/普通的顶部菜单")]
    private static void MenuItemNormal()
    {
        Debug.Log("普通的顶部菜单");
    }

    MenuItem菜单的先后顺序

    需要注意的就是 unity 的顶部菜单的父一级,是不支持中文的,就是 MenuItem 那一级,它的子级就没关系了

    [MenuItem("MenuItem/MenuItem2", false, 2)]
    private static void MenuItemFunc2()
    {
        Debug.Log("MenuItemFunc2");
    }
    [MenuItem("MenuItem/MenuItem1", false, 1)]
    private static void MenuItemFunc1()
    {
        Debug.Log("MenuItemFunc1");
    }
    如图中所示,虽然我们在写代码的时候是 item2 在前,但是我们在设置顺序时给它设的是2,所以最后显示的时候,则是1在前,2在后
    貌似间隔10个,自动分割线

    MenuItem与快捷键

    [MenuItem("MenuItem/快捷键1 _%#&_HOME")]
    private static void MenuItemFunc3()
    {
        Debug.Log("MenuItemFunc3");
    }
    [MenuItem("MenuItem/快捷键2 _%#&_LEFT")]
    private static void MenuItemFunc4()
    {
        Debug.Log("MenuItemFunc4");
    }

    入图所示,这2个item选项跟快捷键关联起来了,可以直接使用快捷键来调用。
    规则是:
    % = ctrl
    # = Shift
    & = Alt
    LEFT/RIGHT/UP/DOWN = 上下左右
    F1…F2 = F...
    HOME, END, PGUP, PGDN = 键盘上的特殊功能键
    特别注意的是,如果是键盘上的普通按键,比如 a~z ,则要写成 _a ~ _z 这种带_前缀的

    选中的不是指定类型的对象,菜单项被禁掉

    [MenuItem("MenuItem/Selected GameObject")]
    private static void SelectedGameObject()
    {
        Debug.Log("SelectedGameObject");
    }
    [MenuItem("MenuItem/Selected GameObject", true)]
    private static bool CheckObjectType()
    {
        Object selectedObject = Selection.activeObject;
        if(selectedObject != null && 
            selectedObject.GetType() == typeof(GameObject))
        {
            return true;
        }
        return false;

    这段的意思就是,如果你没有选中任何游戏对象,或者你选中的不是 GameObject 类型的对象时, MenuItem/Selected GameObject 选项会是被禁用的(灰色)状态,只有选的是指定类型的选项时,才是正常的可点击状态。



    在Inspector窗口中指定控件身上右键选项

    [MenuItem("CONTEXT/Rigidbody/在Rigidbody上右键")]
    private static void CONTEXT_Rigidbody_right_btn()
    {
        Debug.Log("在Rigidbody上右键");
    }


    有时候,我们想在某个控件上增加一些功能菜单,做一些比如自动给控件赋值等这种功能。
    思路跟上面的其实是一样的,只不过我们这次的父换成了CONTEXT而已。


    通过在 GameObject/UI 选项夹里增加选项,使菜单在Hierarchy窗口中被右键到

    [MenuItem("GameObject/UI/在GameObject目录里右键")]
    private static void GameObject_right_btn()
    {
        Debug.Log("在GameObject目录里右键");
    }
    
    思路跟前面一样,我们在  GameObject/UI/  目录下增加了一个选项,我们发现不止在 Hierarchy 窗口中看到了它,在顶部菜单栏相同的层次下也看到了它。
    但是这里有个问题就是,我们并不能够像  GameObject/XXX  这样,把选项放在  UI  的外面,这样做的话,我们只会在顶部栏的  GameObject  目录下发现那个 XXX 的选项,在 Hierarchy 什么也不会有,这点需要大家注意。

    菜单创建窗口

    public class MenuTest : EditorWindow {
    	
    	[MenuItem("Release/hello")]
    	static void Execute()
    	{
    		EditorWindow.GetWindow(typeof(MenuTest), false, "hello").Show();
    	}
    }

    显示空窗口


    SceneView

    如果你想让你的GUI的东西总是显示在场景窗口你可以做如下:

    public class MyClass{
        static MyStaticConstructor() {
            SceneView.onSceneGUIDelegate += OnScene;
        }
        static void OnScene(SceneView sceneView) {
            // Draw GUI stuff here for Scene window display
        }
    }

    此代码将运行,只要你按活动,将吸引任何你希望在你的场景的窗口。
    如何做到scene view中事件响应,映射到创建的窗体,ctrl + 鼠标左键单击

    	[MenuItem("Release/hello")]
    	static void Execute()
    	{
    		MenuTest test = EditorWindow.GetWindow (typeof(MenuTest), false, "hello") as MenuTest;
    
    		SceneView.onSceneGUIDelegate += test.OnSceneGUI;
    		test.Show();
    
    	}
    	private void OnSceneGUI(SceneView sv)
    	{
    		switch (Event.current.type)
    		{
    		case EventType.mouseDown:
    		{
    			if (Event.current.control && Event.current.button == 0)
    			{
    				Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
    				
    				RaycastHit hitInfo;
    				if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity))
    				{
    					Event.current.Use();
    					Repaint();
    				}
    			}
    		}
    			break;
    		}
    	}

    0 means left mouse button, 1 means right mouse button, 2 means middle mouse button. Used in EventType.MouseDownEventType.MouseUp events.

    0表示鼠标左键,1表示鼠标右键,2表示鼠标中键。在EventType.MouseDownEventType.MouseUp事件中使用。





    展开全文
  • 材质UI NestedMenuItem 请参阅示例以了解如何使用: : 更多文档待定。
  • wpf菜单MenuItem样式经典

    热门讨论 2011-12-02 21:30:09
    wpf菜单MenuItem样式经典源代码,绝对经典,
  • <MenuItem name="1-1" to="/tables" tag="tables"> <Icon type="ios-navigate"></Icon> 物料主檔</span> </MenuItem> <MenuItem name="1-2" to="/customer" tag="customer"> ...
  • 菜单MenuItem

    2020-03-17 17:12:00
    添加到自建菜单下 using UnityEditor; using UnityEngine;... [MenuItem("Tools/test")] static void Test() { Debug.Log("test"); } } 添加到已有菜单下,并设置优先级 默认优先级为1000,一般为...

    添加到自建菜单下

    using UnityEditor;
    using UnityEngine;
    
    public class MenuItemTest
    {
        [MenuItem("Tools/test")]
        static void Test()
        {
            Debug.Log("test");
        }
    }
    

    添加到已有菜单下,并设置优先级

    默认优先级为1000,一般为菜单最底一项

    [MenuItem("GameObject/ts1")]
    static void ts1()
    {
        Debug.Log("ts1");
    }
    
    1. 菜单下的菜单项按照优先级分组,每组间隔10
    2. 在Hierarchy窗口鼠标右键显示的是GameObjec菜单的内容;在Projec窗口鼠标右键显示的是Assets菜单的内容,不过需要在特定组的才会显示。

    eg:

    [MenuItem("GameObject/ts1",false,6)]
    static void ts1()
    {
        Debug.Log("ts1");
    }
    

    添加到右键脚本组件时的菜单栏中

    在这里插入图片描述
    代码:
    [MenuItem(“CONTEXT/脚本名/xxx”)]

    sing UnityEditor;
    using UnityEngine;
    
    public class ScriptEditorTest
    {
        [MenuItem("CONTEXT/脚本名/xxx")]
        static void fun1()
        {
            Debug.Log("fun1");
        }
    }
    

    MenuCommand的使用

    使用MenuCommand可以获取右键的组件对象
    eg:右键菜单修改Rigidbody的属性

    [MenuItem("CONTEXT/Rigidbody/xxx")]
        static void fun2(MenuCommand cmd)
        {
            Rigidbody rigidbody = cmd.context as Rigidbody;
            rigidbody.mass = 1.0f;
            rigidbody.useGravity = false;
        }
    
    展开全文
  • WPF menuItem

    2013-08-02 16:53:01
    自己项目中做的WPF菜单项目测试
  • WPF-单选MenuItem

    千次阅读 2019-08-23 17:56:10
    自带的样式不太好看,于是自己就想修改一下,让它默认只有一个子项处于选中状态,再次打开会记录当前选中的是那个MenuItem.思路就是嵌入一个RadioButton控件并让其不可见,控制它的IsChecked属性与MenuItem的...

    这几天在做一个工具栏,用到了Menu控件,我们都知道它是条目控件,可以绑定数据源。自带的样式不太好看,于是自己就想修改一下,让它默认只有一个子项处于选中状态,再次打开会记录当前选中的是那个MenuItem.思路就是嵌入一个RadioButton控件并让其不可见,控制它的IsChecked属性与MenuItem的IsChecked属性之间的关系,支持添加Icon。

    • Xaml及样式
    <Window x:Class="WpfApp1Blend.Window1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:WpfApp1Blend"
            mc:Ignorable="d"
            Title="Window1" Height="450" Width="800">
        <Window.Resources>
            <SolidColorBrush x:Key="Window.ToolBar.Selected.FgColor" Color="#42a4ff"></SolidColorBrush>
            <SolidColorBrush x:Key="Window.ToolBar.Selected.BgColor" Color="#0E2E58"></SolidColorBrush>
            <SolidColorBrush x:Key="Window.ToolBar.MouseOver.BgColor" Color="#0a2243"></SolidColorBrush>
            <SolidColorBrush x:Key="Window.ToolBar.BorderBrushColor" Color="#0d3256"></SolidColorBrush>
            <SolidColorBrush x:Key="Window.ToolBar.BgColor" Color="#031527"></SolidColorBrush>
            <SolidColorBrush x:Key="Control.Static.FgColor" Color="#A5C0E2"></SolidColorBrush>
    
            <Style x:Key="TextBlock.Static13" TargetType="TextBlock">
                <Setter Property="Foreground" Value="{StaticResource Control.Static.FgColor}" />
                <Setter Property="FontFamily" Value="Microsoft YaHei"></Setter>
                <Setter Property="TextWrapping" Value="Wrap" />
                <Setter Property="VerticalAlignment" Value="Center" />
                <Setter Property="HorizontalAlignment" Value="Center" />
                <Setter Property="Margin" Value="5"></Setter>
                <Setter Property="FontSize" Value="13" />
            </Style>
            <Style TargetType="{x:Type Menu}">
                <Setter Property="Background" Value="{StaticResource Window.ToolBar.BgColor}"></Setter>
            </Style>
            <Style TargetType="{x:Type MenuItem}">
                <Setter Property="IsCheckable" Value="True"></Setter>
                <Setter Property="HorizontalAlignment" Value="Center"></Setter>
                <Setter Property="VerticalAlignment" Value="Center"></Setter>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type MenuItem}">
                            <Border x:Name="Border_Ground" Background="Transparent">
                                <StackPanel>
                                    <Grid Margin="10,3">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="auto"></ColumnDefinition>
                                            <ColumnDefinition Width="auto"></ColumnDefinition>
                                            <ColumnDefinition></ColumnDefinition>
                                        </Grid.ColumnDefinitions>
                                        <RadioButton x:Name="rdo" IsChecked="{Binding IsChecked,RelativeSource={RelativeSource Mode=TemplatedParent},Mode=OneWay}" GroupName="A" IsThreeState="False" VerticalAlignment="Center" ></RadioButton>
                                        <Image Grid.Column="1" Source="{Binding Icon,RelativeSource={RelativeSource Mode=TemplatedParent}}" Stretch="None" Margin="0,0,0,0"/>
                                        <TextBlock x:Name="tb" Grid.Column="2"  Text="{TemplateBinding Header}" Style="{StaticResource TextBlock.Static13}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    </Grid>
                                    <Popup x:Name="popup" AllowsTransparency="True"   PopupAnimation="Fade" StaysOpen="False" VerticalOffset="5" IsOpen="{TemplateBinding IsChecked}" AutomationProperties.HelpText="121212">
                                        <Border Background="{StaticResource Window.ToolBar.BgColor}">
                                            <ItemsPresenter></ItemsPresenter>
                                        </Border>
                                    </Popup>
                                </StackPanel>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsChecked" SourceName="rdo" Value="true">
                                    <Setter TargetName="Border_Ground" Property="Background" Value="{DynamicResource Window.ToolBar.Selected.BgColor}"/>
                                    <Setter TargetName="tb" Property="Foreground" Value="{DynamicResource Window.ToolBar.Selected.FgColor}"/>
                                    <Setter Property="IsChecked"  Value="True"></Setter>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="true">
                                    <Setter TargetName="tb" Property="Foreground" Value="{DynamicResource Window.ToolBar.Selected.FgColor}"/>
                                </Trigger>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="Border_Ground" Property="Background" Value="{DynamicResource Window.ToolBar.MouseOver.BgColor}"/>
                                    <Setter TargetName="Border_Ground" Property="BorderBrush" Value="{DynamicResource Window.ToolBar.BorderBrushColor}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    
        </Window.Resources>
        <Grid Width="400" Height="400">
            <StackPanel>
                <Menu>
                    <MenuItem Header="A">
                        <MenuItem Header="A-1"/>
                        <MenuItem Header="A-2"/>
                    </MenuItem>
                    <MenuItem Header="B">
                        <MenuItem Header="B-1"></MenuItem>
                        <MenuItem Header="B-2"></MenuItem>
                        <MenuItem Header="B-3"></MenuItem>
                        <MenuItem Header="B-4"></MenuItem>
                    </MenuItem>
                </Menu>
            </StackPanel>
        </Grid>
    </Window>
    •  效果

    不足之处就是弹出popup面板之后,需要点击外部两次才能隐藏popup,我想第一点击是radiobutton失去焦点,再次点击是为了隐藏popup控件。有兴趣的同学可以自己再优化一下。

    Git:https://github.com/LXX1029/MenuItemSingleSelect.git

    展开全文
  • Unity:菜单MenuItem的使用

    千次阅读 2018-07-13 16:19:49
    最简单的用法:[MenuItem("Tools/ClearPlayerPrefs")]此外,还有很多用法。添加快捷键%-CTRL 在Windows / CMD在OSX# -Shift&amp; -AltLEFT/RIGHT/UP/DOWN-光标键F1…F12HOME,END,PGUP,PDDN注:字母键...
  • MenuItem的使用一、参数介绍二、验证函数三、优先级 一、参数介绍 MenuItem是一个特性,修饰静态方法,可以在Unity顶部菜单出现相应的按钮。 MenuItem有三个参数,分别如下: 1:路径: string 类型。用 ‘/’ 来...
  • iview 升级指南 —— MenuItem

    千次阅读 2018-08-05 15:38:33
    iview 在今年 7 月 28 号发布了 3.0.0 版本,大...本篇是系列文章的第三篇,重点并不在介绍 MenuItem 的功能特性,而在于对其代码的讨论; 对其设计的思考。 班门弄斧,见谅。 唯一新增的特性 —— 支持链接模式 ...
  • Unity MenuItem属性

    2019-07-23 01:11:30
    MenuItem是UnityEditor下的属性,它是对编辑器的扩展,主要有两大作用: 第一,在主菜单中添加菜单项,也就是在以下编辑器部分添加,这是一个很重要的用途,在开发插件的时候经常用到。 示例代码如下: ...
  •  给MenuItem内部的子Image设置默认图标(鼠标leave)、鼠标hover图标、和选中时的图标。  注:是给Menu内个别MenuItem修改,并且是弹出子菜单。 问题描述:  1)前提:Image绑定数据源成功,且Image设置默认...
  • require("menuitem").Menuitem({ id: "myextprefix-some-mi-id", menuid: "menu_FilePopup", insertbefore: "menu_FileQuitItem", "label": _("label"), "accesskey": _("label.ak"), image: self.data.url(...
  • WPF MenuItem传参

    2020-01-08 19:38:53
    <StackPanel.ContextMenu> <ContextMenu> <MenuItem Header="复制" Command="{Binding Source={x:Reference userControl},Path=DataContext.函数}" CommandParameter="{B...
  • 扩展Unity的菜单MenuItem MenuItem 属性用于向主菜单和检视面板上下文菜单添加菜单项。 该 MenuItem 属性能够将任何静态函数转变为菜单命令,仅静态函数可使用 MenuItem 属性 我的Unity版本:2019.3.7f1 创建菜单这...
  • MenuItem MenuItem 属性用于向主菜单和检视面板上下文菜单添加菜单项。 该 MenuItem 属性能够将任何静态函数转变为菜单命令。仅静态函数可使用 MenuItem 属性。 要创建热键,您可以使用以下特殊字符:%(在 Windows ...
  • 我在配置一个ContextMenu,想实现动态后台添加MenuItem。 然而我遇到了这个问题: [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-OwH8y74r-1621672714862)...
  • 菜单MenuItem的使用

    2019-12-19 09:41:42
    1、Unity:菜单MenuItem的使用 2、unity3d拓展编辑器MenuItem的使用:成功 ①亲测+补充:有效 3、Unity 经典教程 Editor扩展之MenuItem的使用:成功 ①亲测+补充:因为例子没有可复制的代码,下面贴上我写的代码...
  • 1. 需求 ...顺便一提,要使MenuItem可以多选,只需要将MenuItem的IsCheckable属性设置为True: <MenuItem IsCheckable="True"/> 不知出于何种考虑,WPF没有为MenuItem提供单选的功能。为了在M...
  • WPF 自定义MenuItem样式

    2019-04-17 14:15:00
    WPF 自定义MenuItem样式 原文:WPF 自定义MenuItem样式一、前言 默认的MenuItem样式比较普通,这次自定义MenuItem的样式也只是对MenuItem的颜色风格进行变化。需要其他功能的变化,大家可以根据样式...
  • MenuItem相关 使用MenuItem在编辑模式下添加选项按钮,实现不同的功能以满足开发需求。 注意: 1.使用MenuItem需要引入UnityEditor命名空间 2.添加的选项按钮执行的函数不需要管私有或者公有的,但需要是静态的,...
  • 此菜单项需要是一个静态的方法且必须使用MenuItem属性来标识。例如,去添加一个你的团队和公司经常使用的命令到“Tools”菜单。  下面的示例,在Tools菜单下添加了一个“Clear PlayerPrefs”选项: public ...
  • MenuItem和ContextMenu

    2017-08-21 09:36:44
    首先是unity顶部菜单栏的一些用法,如图: 注意:MenuItem是编辑器类,所以技能导入 using UnityEditor; 命名空间,且一般我们的类也不是集成自...[MenuItem("MenuItem/普通的顶部菜单")] private static v

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 64,838
精华内容 25,935
关键字:

menuitem