WPF this.Controls Not Come [英] WPF this.Controls Not Come

查看:65
本文介绍了WPF this.Controls Not Come的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WPF应用程序中使用C# this.Controls 不进来.CS文件



我想通过字符串访问控件我做了,

例如this.Controls.Find(txtUserName)。Content =ABC;



但是这个.Controls 不是代码





this。 Controls .Find(ANY STING) 。 ------ ANY ------



请给我解决方案



谢谢您

In WPF Application with C# this.Controls Not Come in .CS File

I want to just access the control by string which i made,
e.g this.Controls.Find("txtUserName").Content = "ABC";

But this.Controls Not Code


this.Controls.Find("ANY STING"). ------ANY------

Please give me Solution

Thank You

推荐答案

搜索VisualTreeHelper并逐步执行控件。这是一个例子:

http://social.msdn.microsoft.com/Forums/vstudio/en-US/a5fd5413-f055-4b56-83af-6d6bdb1d6fe9/wpf-datagrid-onmouseover -background-row-color?forum = wpf [ ^ ]
Search for VisualTreeHelper and step through the controls. Here is one example:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/a5fd5413-f055-4b56-83af-6d6bdb1d6fe9/wpf-datagrid-onmouseover-background-row-color?forum=wpf[^]


for (int a = 0; a < VisualTreeHelper.GetChildrenCount(PARENTCONTROLNAME); a++)
{
    lbl = VisualTreeHelper.GetChild(<pre lang="xml">PARENTCONTROLNAME, a) as Label;
  
    if (lbl != null)
    {
      if (lbl.Name.Equals(YOURSTRING)
      {
           // YOUR CODE TO BE PERFORMED
      }
    }
}


这篇关于WPF this.Controls Not Come的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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