WPF上位机自定义控件系列:菜单 WxMenu 和 WxContextMenu

您所在的位置:网站首页 grid控件的使用 WPF上位机自定义控件系列:菜单 WxMenu 和 WxContextMenu

WPF上位机自定义控件系列:菜单 WxMenu 和 WxContextMenu

2023-03-29 20:57| 来源: 网络整理| 查看: 265

WPF 上位机自定义控件系列菜单 WxMenu右键菜单 WxContextMenu

主要是设计 MenuItem 的样式,还挺复杂的,要考虑不同层级的 Header、Item,考虑 IsChecked 功能

参考了 HandyControl 里的样式,并增加了 Iconfont 属性来简化 Icon 的添加过程

WxMenuItem 控件using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace WpfControlsX.ControlX { public class WxMenuItem : MenuItem { static WxMenuItem() { DefaultStyleKeyProperty.OverrideMetadata(typeof(WxMenuItem), new FrameworkPropertyMetadata(typeof(WxMenuItem))); } /// /// 图标 /// public Geometry Iconfont { get => (Geometry)GetValue(IconfontProperty); set => SetValue(IconfontProperty, value); } public static readonly DependencyProperty IconfontProperty = DependencyProperty.Register("Iconfont", typeof(Geometry), typeof(WxMenuItem), new PropertyMetadata(null)); /// /// 图标尺寸 /// public double IconSize { get => (double)GetValue(IconSizeProperty); set => SetValue(IconSizeProperty, value); } public static readonly DependencyProperty IconSizeProperty = DependencyProperty.Register("IconSize", typeof(double), typeof(WxMenuItem), new PropertyMetadata(10d)); /// /// Header 宽度 /// public double HeaderWidth { get => (double)GetValue(HeaderWidthProperty); set => SetValue(HeaderWidthProperty, value); } public static readonly DependencyProperty HeaderWidthProperty = DependencyProperty.Register("HeaderWidth", typeof(double), typeof(WxMenuItem), new PropertyMetadata(24d)); } } WxMenuItem、WxMenu、WxContextMenu 样式 使用



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3