[英]Searching controls by name in Windows Phone c# application
Is it possible to search controls by name in Windows Phone application? 是否可以在Windows Phone应用程序中按名称搜索控件? I know it's possible in normal desktop application written in c#:
我知道用c#编写的普通桌面应用程序有可能:
string s = "label2";
Control[] controls = this.Controls.Find(s, false);
if (controls.Length > 0)
{
Label found = controls[0] as Label;
if (found != null) found.Text = "new label2 text";
}
In Windows Phone application 'this.Controls' is unrecognized... 在Windows Phone应用程序中,无法识别“ this.Controls” ...
Yes, it is possible - but with Windows Phone your controls are located within a tree-like structure called the visual tree. 是的,这是可能的-但是使用Windows Phone,您的控件位于称为可视树的树状结构内。 In order to find a control, you have to navigate this tree.
为了找到控件,您必须导航此树。 I wrote a utility class a while bcd called Linq-to-VisualTree that simplifies this process.
我写了一个名为Linq-to-VisualTree的实用程序类bcd,它简化了这一过程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.