Click here to Skip to main content
15,902,492 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 24-Oct-13 2:59am
v3
Comments
Kenneth Haugland 24-Oct-13 9:00am    
Im really saying it does not exist in WPF... So you cant.
Hitesh Vaghasiya 24-Oct-13 9:02am    
I want to just access the control by string which i made,
e.g this.Controls.Find("txtUserName").Content = "ABC";

Do you have other method ????
Kenneth Haugland 24-Oct-13 9:03am    
Yes, the VisualTreeHelper

 
Share this answer
 
C#
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
      }
    }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900