c# – WPF – 如何从按钮处理程序中确定列表框中当前项的索引
发布时间:2020-12-16 01:29:34 所属栏目:百科 来源:网络整理
导读:我有一个列表框,其中包含一个包含按钮的数据模板. 单击按钮时,我想进入按钮 click handler当前列表框项的索引? 我该怎么办? 马尔科姆 解决方法 更合适的答案, private void Button_Click(object sender,RoutedEventArgs e){ DependencyObject dep = (Depen
我有一个列表框,其中包含一个包含按钮的数据模板.
单击按钮时,我想进入按钮 我该怎么办? 马尔科姆 解决方法
更合适的答案,
private void Button_Click(object sender,RoutedEventArgs e) { DependencyObject dep = (DependencyObject)e.OriginalSource; while ((dep != null) && !(dep is ListViewItem)) { dep = VisualTreeHelper.GetParent(dep); } if (dep == null) return; int index = lstBox.ItemContainerGenerator.IndexFromContainer(dep); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 新建ORACLE数据库实例时ORA-12154: TNS: 无法解析指定的连接
- ruby-on-rails – 如何使重定向包括名称而不是ID?
- net.sf.json.JSONException: There is a cycle in the hier
- 使用cocos2d-js制作游戏新手引导(一)
- R使用日期列聚合data.frame
- 使用Flash地图控件AnyMap在地图上添加自定义区域
- VB.NET之错误异常处理
- XML基本概念解析(一) SAX、DOM、DTD和Schema
- ruby-on-rails – 用于备份和恢复数据库的Rake任务
- Swift 3 Parallel for / map Loop