首页 > 其他分享 >WPF ContextMenu MenuItem style based on

WPF ContextMenu MenuItem style based on

时间:2024-04-15 16:24:43浏览次数:18  
标签:MenuItem WPF based style ContextMenu

<Window x:Class="WpfApp58.MainWindow"
        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:WpfApp58"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <Style TargetType="{x:Type MenuItem}" x:Key="miStyle">
            <Setter Property="FontSize" Value="20"/>
            <Setter Property="Foreground" Value="Blue"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="FontSize" Value="50"/>
                    <Setter Property="Foreground" Value="Red"/>
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style TargetType="{x:Type MenuItem}" x:Key="miStyle2">
            <Setter Property="FontSize" Value="20"/>
            <Setter Property="Foreground" Value="Blue"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="FontSize" Value="50"/>
                    <Setter Property="Foreground" Value="Green"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition/>
            <RowDefinition Height="50"/>
        </Grid.RowDefinitions>
        <DataGrid Grid.Row="1" ItemsSource="{Binding BooksCollection,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                  VerticalAlignment="Stretch" HorizontalAlignment="Stretch" BorderBrush="Blue"
                   BorderThickness="3">
            <DataGrid.ContextMenu>
                <ContextMenu>
                    <ContextMenu.ItemContainerStyle>
                        <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource miStyle}"/>
                    </ContextMenu.ItemContainerStyle> 
                    <MenuItem Header="Export Single" />
                    <MenuItem Header="Export Multiple" Style="{StaticResource miStyle2}"/>
                    <MenuItem Header="Copy"/>
                </ContextMenu>
            </DataGrid.ContextMenu>
        </DataGrid>
    </Grid>
</Window>

 

 

 

 

标签:MenuItem,WPF,based,style,ContextMenu
From: https://www.cnblogs.com/Fred1987/p/18136214

相关文章

  • WPF开发时候遇到的问题
    1.DataGrid下的DataGridTemplateColumn的ComboBox绑定问题最开始的形式<DataGridTemplateColumnHeader="截面名称"><DataGridTemplateColumn.CellTemplate><DataTemplate><ComboBoxHorizontalAlignment=&q......
  • WPF,Frame控件的一个BUG
    我使用WPF默认的frame<FrameStyle="{DynamicResourceFrameStyle1}"x:Name="frame"Height="80"NavigationUIVisibility="Visible"/>然后添加几次导航Task.Run(async()=>{this.Dispatcher.BeginInvoke(()=>this.frame.N......
  • Causal Inference理论学习篇-Tree Based-Causal Tree
    Tree-BasedAlgorithmsTree-based这类方法,和之前meta-learning类的方法最明显的区别是:这类方法把causaleffect的计算显示的加入了到了树模型节点分裂的标准中从response时代过渡到了effect时代。大量的这类算法基本围绕着树节点分裂方式做文章,普遍采用的是兼容性比较高......
  • C# 面试 wpf .net 面试准备
    杂项介绍下自己时间一分半以内提炼自身优点,优势、亮点、基本情况言简意赅、语言精炼,控制时间和应聘岗位相关的经历(和招聘要求相关)为什么能够胜任岗位为什么要应聘该岗位~求职动机不能只介绍学校和专业,注意:重点介绍满足岗位要求的三个优势和亮点。表现出对岗位的理解和......
  • Evolutionary many-objective optimization algorithm based on angle and clustering
    Evolutionarymany-objectiveoptimizationalgorithmbasedonangleandclustering本文的工作本文提出了一种新的MaOEA,它使用锐角作为相似度量。通过聚类方法,最终将种群划分为若干个聚类,每个聚类中仅选择一个个体,以保持环境选择的趋同性和多样性。据我们所知,我们首先尝试利......
  • WPF新建viewModel实例化成员的注意事项
    不要用表达式体去初始化一个用做数据源(比如ItemSource)的引用类型成员。比如这种publicList<MainWindowItem>Items=>newList<MainWindowItem>(){newMainWindowItem{title="项目管理",icon="\ue613",type=typeof(项目管理Control),group="内部管理"},new......
  • WPF深入浅出的 6.3.3 Binding的路径(Path)
    根据WPF的6.3.3Binding的路径(Path)代码验证结果 publicclassCity{publicstringName{get;set;}}publicclassProvince{publicstringName{get;set;}publicList<City>CityList{get;set;}}publ......
  • 52 Things: Number 50: What is the BLS pairing-based signature scheme?
    52Things,Number50:WhatistheBLSpairing-basedsignaturescheme?52件事,第50号:什么是基于BLS配对的签名方案? ThisweekwelookatwhattheBLSpairing-basedsignatureschemeis.See here forfulldetails.本周我们来看看什么是基于BLS配对的签名方案。请参......
  • 52 Things: Number 51: What is the security model for ID-based encryption, and de
    52Things:Number51:WhatisthesecuritymodelforID-basedencryption,anddescribeoneIBEscheme.52件事:第51件:基于ID的加密的安全模型是什么,并描述一个IBE方案。 Thisisthelatestinaseriesofblogpoststoaddressthelistof '52ThingsEveryPhDStu......
  • 52 Things: Number 32: difference between game-based and simulation-based securit
    52Things:Number32:differencebetweengame-basedandsimulation-basedsecuritydefinitions52件事:数字32:基于游戏和基于模拟的安全定义之间的区别 Thisisthelatestinaseriesofblogpoststoaddressthelistof'52ThingsEveryPhDStudentShouldKnowt......