如何在wpf中引用子控件 [英] how to refer the child controls in wpf

查看:337
本文介绍了如何在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.com/en-us/library/ms753391.aspx [ ^ ]。



此CodeProject文章也很有用:了解WPF中的可视树和逻辑树 [ ^ ]。



-SA
Please see: http://msdn.microsoft.com/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中引用子控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆