当前位置: 首页 > news >正文

做网站的控件专门做推广的公司

做网站的控件,专门做推广的公司,福州市晋安区建设局网站,网站建设完整版一、目的:开发过程中,有些模块的右键ContextMenu菜单是需要动态显示的,既是根据不同条件显示不同的菜单,很多是通过代码去生成ContextMenu的MenuItem,本文介绍通过绑定的方式去加载ContextMenu,Menu菜单栏的…

一、目的:开发过程中,有些模块的右键ContextMenu菜单是需要动态显示的,既是根据不同条件显示不同的菜单,很多是通过代码去生成ContextMenu的MenuItem,本文介绍通过绑定的方式去加载ContextMenu,Menu菜单栏的同样适用,原理同TreeView的绑定


二、效果

三、环境
VS2022

四、实现

实现代码

            <TextBlock Text="右键弹出菜单"><TextBlock.ContextMenu><ContextMenu ItemsSource="{local:ClassTypeTreeDataProvider IsRecursion=True, Type={x:Type FrameworkElement}}"><ContextMenu.ItemContainerStyle><Style TargetType="MenuItem"><Setter Property="Command" Value="{local:ShowDialogCommand}"/><Setter Property="CommandParameter" Value="{Binding Model}"/></Style></ContextMenu.ItemContainerStyle><ContextMenu.ItemTemplate><HierarchicalDataTemplate ItemsSource="{Binding Nodes}"><DockPanel><CheckBox VerticalAlignment="Center" IsChecked="{Binding IsChecked, Mode=TwoWay}" /><TextBlock  VerticalAlignment="Center" Text="{Binding Model.Name}" /></DockPanel></HierarchicalDataTemplate></ContextMenu.ItemTemplate></ContextMenu></TextBlock.ContextMenu></TextBlock>

 原理跟TreeView一样,应用ItemsSource绑定数据源,应用HierarchicalDataTemplate模板作为ItemTemplate来绑定,树结构的绑定参考文档

示例:WPF中TreeView自定义TreeNode泛型绑定对象-CSDN博客

示例:WPF中TreeView自定义TreeNode泛型绑定对象来实现级联勾选-CSDN博客

Menu的绑定原理一样

实现代码

            <Menu ItemsSource="{local:ClassTypeTreeDataProvider IsRecursion=True, Type={x:Type FrameworkElement}}"><Menu.ItemContainerStyle><Style TargetType="MenuItem"><Setter Property="Command" Value="{local:ShowDialogCommand}"/><Setter Property="CommandParameter" Value="{Binding Model}"/></Style></Menu.ItemContainerStyle><Menu.ItemTemplate><HierarchicalDataTemplate ItemsSource="{Binding Nodes}"><TextBlock  VerticalAlignment="Center" Text="{Binding Model.Name}" /></HierarchicalDataTemplate></Menu.ItemTemplate></Menu>

当切换ItemsSource既可以实现动态切换ContextMenu 

五、需要了解的知识点

ContextMenu 类 (System.Windows.Controls) | Microsoft Learn

Menu 类 (System.Windows.Controls) | Microsoft Learn

HierarchicalDataTemplate 类 (System.Windows) | Microsoft Learn

MenuItem 类 (System.Windows.Controls) | Microsoft Learn

ICommand 接口 (System.Windows.Input) | Microsoft Learn

六、源码地址

GitHub - HeBianGu/WPF-ControlDemo: 示例

GitHub - HeBianGu/WPF-ControlBase: Wpf封装的自定义控件资源库

GitHub - HeBianGu/WPF-Control: WPF轻量控件和皮肤库

七、了解更多

System.Windows.Controls 命名空间 | Microsoft Learn

https://github.com/HeBianGu

HeBianGu的个人空间-HeBianGu个人主页-哔哩哔哩视频

http://www.15wanjia.com/news/182216.html

相关文章:

  • 临沂河东区建设局网站龙华区深圳北站
  • 有个能写文章做任务的网站公司起名字库
  • 公明 网站建设哪些公司做网站
  • 中国建设基础设施公司网站深圳正规网站建设公司
  • 优秀购物网站phpcms 视频网站模板下载
  • 专门做搜索种子的网站有哪些洛阳建设银行官方网站
  • 做的好的公司网站公司管理制度
  • 江西做企业网站的公司手机网站友情链接怎么做
  • 上海网站se0优化蛋糕店网站开发策划书
  • 网站平台被骗了怎么办天行健公司网站建设
  • 大连模板网站制作费用郑州seo排名第一
  • seo网站建设教程建设工程的招标网站有哪些
  • 网站侧边菜单关于服装店网站建设的策划方案
  • 长沙p2p网站建设wordpress仪表盘
  • 现在 做网站 最流行ui在线设计网站
  • 耒阳市做网站的超酷 flash 网站
  • asp作业做购物网站代码网站建设攵金手指专业
  • 网站空间大小选择石家庄建筑网
  • 苍山做网站网站 毕业设计代做
  • 沈阳求做商城 网站wordpress关于本站
  • 成都人才网站建设河北网络营销推广seo
  • 墨刀怎么做网站注册一个设计公司需要多少钱
  • wordpress开发工作流6seo站
  • 经销商怎么做网站毕业设计做网站大小有什么要求
  • 网站的做公司注册传媒公司需要多少钱
  • 有什么做糕点的视频网站网页设计作业百度云
  • 舟山做网站网站安装百度商桥
  • 宁波网站排名优化成都网站建设常见问题
  • 南京网站排名提升wordpress两个title
  • 网站开发怎么做网站地址栏图标文字