<TreeView x:Name="CustomTreeView"
Canvas.Top="1" Canvas.Bottom="1" VerticalAlignment="Stretch"
Margin="10,45,10,10"
MouseRightButtonDown="TView_MouseRightButtonDown">

//添加事件

private void TView_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
object item = GetElementFromPoint((ItemsControl)sender, e.GetPosition((ItemsControl)sender));
isItemSelected = (item != null);
if (!isItemSelected)
{
this.CustomTreeView.ContextMenu = null;
}
}

//根据焦点判断是否有选中对象

private object GetElementFromPoint(ItemsControl itemsControl, Point point)
{
UIElement element = itemsControl.InputHitTest(point) as UIElement;
while (element != null)
{
if (element == itemsControl)
return null;
object item = itemsControl.ItemContainerGenerator.ItemFromContainer(element);
if (!item.Equals(DependencyProperty.UnsetValue))
return item;
element = (UIElement)VisualTreeHelper.GetParent(element);
}
return null;
}

wpf TreeView右键选中节点弹菜单的更多相关文章

  1. WPF 之 TreeView右键选中节点及节点重命名

    下面的TreeView节点是通过数据双向绑定的方式,绑定到TextBlock控件和TextBox控件的Text属性上,并且让两者绑定相同的属性,同时使TextBox控件刚好完全覆盖TextBlock控 ...

  2. WPF TreeView Indent 减少节点的缩进

    www.swack.cn - 原文链接:WPF TreeView Indent 减少节点的缩进 问题 最近一个需求,需要在界面中实现Windows资源管理器TreeView的界面.但是我发现,我做出的 ...

  3. C# WinForm设置TreeView选中节点

    这里假定只有两级节点,多级方法类似.遍历节点,根据选中节点文本找到要选中的节点.treeView.SelectedNode = selectNode; /// <summary> /// ...

  4. delphi TreeView修改选中的节点的颜色和背景

      TreeView修改选中的节点的颜色和背景     TCustomDrawTarget = (dtControl, dtItem, dtSubItem);   TCustomDrawStage = ...

  5. TreeView查获节点并选中节点

    TreeView查获节点并选中节点如果有多个节点则会继续查找下一个节点 支持关键字搜索 private void SearchNodes(string SearchText, TreeNode Sta ...

  6. wpf treeview 数据绑定 递归绑定节点

    1.先上效果 将所有节点加入ComboBox数据源,在ComboBox中选择时下方Treeview显示该节点下的子节点. 1.xaml文件,将以下代码加入界面合适位置 <StackPanel&g ...

  7. WPF TreeView 选择事件执行两次,获取TreeView的父节点的解决方法

    1.TreeView选择事件执行两次 Very often, we need to execute some code in SelectedItemChanged depending on the ...

  8. WinForm控件TreeView 只部分节点显示 CheckBox

    WinForm控件TreeView 只部分节点显示  CheckBox 用过asp.net的应该知道,要在treeview中实现上述功能可以使用ShowCheckBox 属性指定那些节点显示check ...

  9. 关于TreeView的选中事件

    在使用TreeView的选中事件时,发现,SelectAfter在第一次选中时触发,你再次点击时这个事件并不能引发它.所以找了找,发现有另两种解决办法. 最好的就是使用:NodeMouseClick, ...

  10. C# TreeView 拖拽节点到另一个容器Panel中简单实现

    C# TreeView 拖拽节点到另一个容器Panel中简单实现 用了这么久C#拖拽功能一直没有用到也就没用过,今天因为项目需要,领导特地给我简单讲解了下拖拽功能,真是的大师讲解一点通啊.特地写一篇博 ...

随机推荐

  1. Ubuntu命令安装默认支持的Qt5版本

    1.前置依赖 sudo apt install build-essential sudo apt install cmake 2.只安装默认的Qt模块 # 安装默认SDK # Ubuntu18.04中 ...

  2. PKU2506Tiling

    https://blog.csdn.net/Harington/article/details/86612106

  3. VSCode 自动编译 typescript 为 javascript

    1.我们默认你已经安装了node.js通过npm安装typescript npm install -g typescript 2.VSCode 里,点击"终端" "新建终 ...

  4. 【Redis的三种数据删除策略】定时定期惰性,超出内存就自动清理

    https://blog.csdn.net/DQWERww/article/details/126453008 https://blog.csdn.net/qq_38056518/article/de ...

  5. Loaded plugins: fastestmirror, langpacks You need to be root to perform this command.

  6. vue3 、typescript环境, props自定义类型propType

    vue3 .typescript环境, props自定义类型propType //子组件的props类型是复杂的类型的时候,可以用propType进行强制类型转换 //eg 复杂函数,对象数组,对象的 ...

  7. python时间加减

    要用到生成时间,在当前日期前/后xx天.xx小时.xx分钟.xx秒 # coding:utf8 from datetime import datetime, timedelta def gen_dat ...

  8. 清除Linux登录记录

    CentOS cat /dev/null > /var/log/wtmp cat /dev/null > /var/log/btmp cat /dev/null > /var/log ...

  9. 浏览器 - 重绘(repaint)重排(reflow)

    浏览器 - 重绘(repaint)重排(reflow) 网页生成过程: HTML被HTML解析器解析成DOM 树 css则被css解析器解析成CSSOM 树 结合DOM树和CSSOM树,生成一棵渲染树 ...

  10. 蓝牙mesh组网实战(智能家居应用)

    目录 蓝牙mesh组网目前存在有入门门槛高的问题,比如,嵌入式工程师需要考虑到标准mesh模型的兼容,app开发工程师需要了解mesh协议栈才能直接走mesh与芯片通信.而沁恒官方提供的透传模型简洁易 ...