如何在wpf中引用子控件

编程入门 行业动态 更新时间:2024-10-25 10:31:04
本文介绍了如何在wpf中引用子控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在listview控件中有复选框。我想找到里面的复选框控件名称 这样的列表视图 for( int k = 0; k< = listView1.Items.Count - 1; k ++) { ListViewData lvc =(ListViewData)listView1.Items [k]; 选项1:var chb_standard =发送者作为CheckBox; option2:CheckBox myTextbox = GetTemplateChild(chb_standard)作为CheckBox; checkBox.IsChecked = true; } 但我无法引用复选框控件名称我只得到null是否有任何想法 参考控制帮助我。提前谢谢

i am having checkbox inside listview control .i want to find the checkbox control name inside list view like this for (int k = 0; k <= listView1.Items.Count - 1; k++) { ListViewData lvc = (ListViewData)listView1.Items[k]; option 1: var chb_standard = sender as CheckBox; option2: CheckBox myTextbox = GetTemplateChild("chb_standard") as CheckBox; checkBox.IsChecked = true; } but i can't able to refer the checkbox control name i am getting only null is there any idea to refer the control help me. thanks in advance

推荐答案

请参阅: http ://msdn.microsoft/en-us/library/ms753391.aspx [ ^ ]。 此CodeProject文章也很有用:了解WPF中的可视树和逻辑树 [ ^ ]。
-SA
Please see: msdn.microsoft/en-us/library/ms753391.aspx[^]. This CodeProject article can also be useful: Understanding the Visual Tree and Logical Tree in WPF[^].
—SA

有几种辅助方法 GetVisualChildren 和 GetVisualDescendants 可用于访问控件中的子元素。 There are a couple of helper methods GetVisualChildren and GetVisualDescendants that you could use to access child elements inside a control.

更多推荐

如何在wpf中引用子控件

本文发布于:2023-11-05 09:33:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560477.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   如何在   wpf

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!