WPF Treeview 点击右键弹出菜单,同时鼠标点击处的TreeViewItem被选中

上传者: tianzhiguo | 上传时间: 2021-08-22 15:12:24 | 文件大小: 51KB | 文件类型: RAR
有时候我们需要在TreeView中实现这样的功能: 在TreeView上点击右键弹出菜单,同时鼠标点击处的TreeViewItem被选中,然后我们针对选中的数据进行处理。 不过,WPF的TreeView并没有提供右键单击选中的功能。我们需要自己去实现。 【思路】 最基本的思路是,在TreeView右键点击的事件发生时,我们遍历它所有的Item,包括子Item,获取Item所对应的TreeViewItem控件的边界Rect,然后调用Rect的Contains方法判断鼠标是否在该范围内。(

文件下载

资源详情

[{"title":"( 29 个子文件 51KB ) WPF Treeview 点击右键弹出菜单,同时鼠标点击处的TreeViewItem被选中","children":[{"title":"TreeViewRightClick","children":[{"title":"TreeViewRightClick.sln <span style='color:#111;'> 944B </span>","children":null,"spread":false},{"title":"TreeViewRightClick.suo <span style='color:#111;'> 12.50KB </span>","children":null,"spread":false},{"title":"TreeViewRightClick","children":[{"title":"bin","children":[{"title":"Debug","children":[{"title":"TreeViewRightClick.vshost.exe <span style='color:#111;'> 13.99KB </span>","children":null,"spread":false},{"title":"TreeViewRightClick.pdb <span style='color:#111;'> 45.50KB </span>","children":null,"spread":false},{"title":"TreeViewRightClick.exe <span style='color:#111;'> 13.00KB </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"DemoWindow.xaml.cs <span style='color:#111;'> 1.72KB </span>","children":null,"spread":false},{"title":"obj","children":[{"title":"Debug","children":[{"title":"TreeViewRightClick.pdb <span style='color:#111;'> 45.50KB </span>","children":null,"spread":false},{"title":"TreeViewRightClick_MarkupCompile.cache <span style='color:#111;'> 351B </span>","children":null,"spread":false},{"title":"TreeViewRightClick.csproj.GenerateResource.Cache <span style='color:#111;'> 789B </span>","children":null,"spread":false},{"title":"DemoWindow.baml <span style='color:#111;'> 1.65KB </span>","children":null,"spread":false},{"title":"TreeViewRightClick.Properties.Resources.resources <span style='color:#111;'> 180B </span>","children":null,"spread":false},{"title":"TreeViewRightClick.exe <span style='color:#111;'> 13.00KB </span>","children":null,"spread":false},{"title":"TreeViewRightClick.csproj.FileListAbsolute.txt <span style='color:#111;'> 1.78KB </span>","children":null,"spread":false},{"title":"App.g.cs <span style='color:#111;'> 2.05KB </span>","children":null,"spread":false},{"title":"Refactor","children":null,"spread":false},{"title":"DemoWindow.g.cs <span style='color:#111;'> 3.78KB </span>","children":null,"spread":false},{"title":"TempPE","children":null,"spread":false},{"title":"TreeViewRightClick.g.resources <span style='color:#111;'> 2.28KB </span>","children":null,"spread":false},{"title":"GeneratedInternalTypeHelper.g.cs <span style='color:#111;'> 2.84KB </span>","children":null,"spread":false},{"title":"TreeViewRightClick_MarkupCompile.lref <span style='color:#111;'> 115B </span>","children":null,"spread":false}],"spread":false}],"spread":true},{"title":"TreeViewRightClick.csproj <span style='color:#111;'> 4.26KB </span>","children":null,"spread":false},{"title":"Properties","children":[{"title":"Resources.Designer.cs <span style='color:#111;'> 2.80KB </span>","children":null,"spread":false},{"title":"Settings.settings <span style='color:#111;'> 201B </span>","children":null,"spread":false},{"title":"Resources.resx <span style='color:#111;'> 5.48KB </span>","children":null,"spread":false},{"title":"Settings.Designer.cs <span style='color:#111;'> 1.08KB </span>","children":null,"spread":false},{"title":"AssemblyInfo.cs <span style='color:#111;'> 2.25KB </span>","children":null,"spread":false}],"spread":true},{"title":"App.xaml <span style='color:#111;'> 302B </span>","children":null,"spread":false},{"title":"App.xaml.cs <span style='color:#111;'> 320B </span>","children":null,"spread":false},{"title":"DemoWindow.xaml <span style='color:#111;'> 1.66KB </span>","children":null,"spread":false},{"title":"TreeViewHelper.cs <span style='color:#111;'> 3.68KB </span>","children":null,"spread":false},{"title":"Data.xml <span style='color:#111;'> 379B </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true}]

评论信息

  • chgcrr :
    不错的,有用处。
    2017-07-01
  • csdn0113 :
    骗人的。。根本没有右击。。也没有菜单
    2017-03-21
  • liuchao_dotnet :
    不是我想要的~难过
    2016-02-23
  • u011794730 :
    没有右键啊,,,还我的5分。。。
    2014-09-01
  • alpha1377 :
    对于初学者很不错,但是能不能在详细点儿
    2014-08-18

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明