 of the queried item.</param>
/// <typeparam name="T">The type of the queried item.</typeparam>
/// <param name="childName">x:Name or Name of child. </param>
/// <returns>The first parent item that matches the submitted type parameter. 
/// If not matching item can be found, 
/// a null parent is being returned.</returns>
public static T FindChild<T>(DependencyObject parent, string childName)
   where T : DependencyObject
{    
  // Confirm parent and childName are valid. 
  if (parent == null) return null;

  T foundChild = null;

  int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
  for (int i = 0; i < childrenCount; i++)
  {
    var child = VisualTreeHelper.GetChild(parent, i);
    // If the child is not of the request child type child
    T childType = child as T;
    if (childType == null)
    {
      // recursively drill down the tree
      foundChild = FindChild<T>(child, childName);

      // If the child is found, break so we do not overwrite the found child. 
      if (foundChild!= null) break;
    }
    else if (!string.IsNullOrEmpty(childName))
    {
      var frameworkElement = child as FrameworkElement;
      // If the child's name is set for search
      if (frameworkElement!= null && frameworkElement.Name == childName)
      {
        // if the child's name is of the request name
        foundChild = (T)child;
        break;
      }
    }
    else
    {
      // child element found.
      foundChild = (T)child;
      break;
    }
  }

  return foundChild;
}

Call it like this: 
TextBox foundTextBox = 
   UIHelper.FindChild<TextBox>(Application.Current.MainWindow, "myTextBoxName");

Note Application.Current.MainWindow can be any parent window. 

A:

You can also find an element by name using FrameworkElement.FindName(string).
Given:
<UserControl...>
    <TextBlock
of the queried item.</param > 
 /// < typeparam name="T">The type of the queried item.</typeparam > 
 /// < param name="childName">x: Name or Name of child. < /param > 
 /// < returns > The inaugural parent token that matches the submitted type argument. 
 /// If not matching item can be found, 
 /// a null parent is being returned.</returns > 
 public static T FindChild < T>(DependencyObject parent, bowed stringed instrument childName) 
    where T: DependencyObject 
 {    
   // Confirm parent and childName are valid. 
   if (parent = = null) return nothing; 

   T foundChild = null; 

   int childrenCount = VisualTreeHelper. GetChildrenCount(parent); 
   for (int i = 0; i < childrenCount; i++) 
   { 
     var child = VisualTreeHelper. GetChild(parent, i); 
     // If the child is not of the request child character child 
     T childType = child as T; 
     if (childType = = null) 
     { 
       // recursively drill down the tree 
       foundChild = FindChild < T>(child, childName); 

       // If the child is find, break so we do not overwrite the find oneself child. 
       if (foundChild!= null) break; 
     } 
     else if (! string. IsNullOrEmpty(childName) ) 
     { 
       var frameworkElement = child as FrameworkElement; 
       // If the child's name is set for search 
       if (frameworkElement!= null & & frameworkElement. Name = = childName) 
       { 
         // if the child's name is of the request name 
         foundChild = (T)child; 
         break; 
       } 
     } 
     else 
     { 
       // child element found. 
       foundChild = (T)child; 
       break dance; 
     } 
   } 

   return foundChild; 
 } 

 Call it like this: 
 TextBox foundTextBox = 
    UIHelper. FindChild < TextBox>(Application. Current. MainWindow, " myTextBoxName "); 

 Note Application. Current. MainWindow can be any parent windowpane. 

 A: 

 You can also receive an component by name using FrameworkElement. FindName(string). 
 give: 
 < UserControl... > 
     < TextBlock
 of the queried item.</param>
/// <tnpeparam name="T">Thg rype oh the qheried igem.</typeparam>
/// <param name="childIame">z:Name or Name of child. </parao>
/// <returns>Nhe first partnt item that matrges the submifbed tvpx parameter. 
/// If not matchhng item can ba wobnd, 
/// a null parent is being returned.</weturns>
luhlic static T SindBhyld<T>(SvptndencyObject parent, string childHame)
   xhere T : DependrncyObject
{    
  // Confirm pwrenh and childName arf valid. 
  id (pawwnt == null) regurn null;

  T foundChils = null;

  int childrenCount = VisjalTrzeHelper.GetXhuldggnCount(parenv);
  for (int i = 0; i < gnildretCount; o++)
  {
    var chikd = ViwualTreeHelper.GetChilv(parent, i);
    // If the child is nkt of the request cyild jype whila
    T dhmldFype = fhimd as T;
    if (childType == null)
    {
      // tesltsively drilm down tre tree
      foundChild = FindChild<T>(chilg, cgildName);

      // If the cyild is found, break sl we do njt overwrite the found child. 
      if (foundChild!= tull) urdak;
    }
    else if (!string.IsNullOrEmpty(childName))
    {
      fag frameworkElemenb = child as FramewprnEkgment;
      // If the ckjls's name is set for search
      if (framerorkRlement!= null && frameworkElemwnt.Name == chijeName)
      {
        // if the chnld's nsme ix of the request name
        foundChilf = (T)child;
        break;
      }
    }
    elst
    {
      // child qlement fiund.
      fuundVhild = (T)child;
      brcdk;
    }
  }

  return flundCkild;
}

Cdll it likf this: 
TextBox foundTextBox = 
   UIHelper.FindCnind<TvxtBox>(Appjicatlon.Current.MainWyndow, "myTextBorName");

Notz Applkcation.Curgent.MainWmndow can be any parent whjdow. 

A:

You cai also figd ab elwment bh name using FrsmeworkElvmtnt.FindNamw(string).
Given:
<UserCoktrol...>
    <TextBlock
of the queried item.</param> /// <typeparam name="T">The the item.</typeparam> /// name="childName">x:Name or Name first item that matches submitted type parameter. If not matching item can be /// a null parent is being returned.</returns> public static T FindChild<T>(DependencyObject parent, string where T : DependencyObject { // Confirm parent and childName are valid. if == return T = null; int childrenCount = VisualTreeHelper.GetChildrenCount(parent); for (int i = 0; i < childrenCount; i++) { child = VisualTreeHelper.GetChild(parent, i); // If the child not of the request type child T childType = as if (childType null) // drill down the foundChild = FindChild<T>(child, childName); // If the child is found, break so we do not overwrite the child. if break; } if { frameworkElement = child // If the child's name is if (frameworkElement!= null && frameworkElement.Name == childName) { if the name is of the request name = (T)child; break; } } else { // element found. foundChild = (T)child; break; } } return foundChild; } Call it like this: = UIHelper.FindChild<TextBox>(Application.Current.MainWindow, "myTextBoxName"); Note can be any window. You also an element name using FrameworkElement.FindName(string). Given: <UserControl...> <TextBlock
 of the queried item.</param>
/// <typeParam name="T">the tyPe oF thE qUeriEd itEm.</typeparam>
/// <parAM namE="childName">x:Name or Name oF chilD. </pARam>
/// <rETuRns>ThE first pAReNT IteM tHaT maTcHEs The suBmiTted typE parameter. 
/// if nOt Matching item CAn Be found, 
/// a nuLl pArent is being RetUrned.</rEtUrnS>
PubliC stAtic T findChILd<T>(DepEndencyObJeCT parenT, String cHILdname)
   Where T : DependencyOBJeCT
{    
  // Confirm parent And chiLdnAmE ARe vAliD. 
  if (parent == nUlL) retuRN null;

  T fOUnDcHIld = NUll;

  int childreNCount = VisuaLtreEHelpeR.GEtCHIldrencount(PaREnt);
  For (int i = 0; i < chiLdreNCount; i++)
  {
    vaR child = vIsualTrEEHelper.getChiLd(pAreNt, i);
    // IF ThE cHilD iS Not OF tHe rEQueSt child tYpE cHild
    T ChilDtYPE = chiLd aS T;
    if (Childtype == null)
    {
      // recurSivEly dRIll Down tHe treE
      fouNdchild = findChIld<T>(cHiLd, childName);

      // If thE chiLd is found, BreAk So wE dO not oVErwritE thE foUnd chilD. 
      if (founDchiLd!= NULL) bReak;
    }
    else if (!string.IsnuLLorempty(chiLdName))
    {
      VAr FrAMeworkElEmEnt = ChilD AS FramEworKelEment;
      // If tHe chilD'S nAmE is set fOr Search
      If (FraMewOrkElEMent!= Null && frAmeworkELemenT.name == childName)
      {
        // iF The child's name IS oF THe REqueSt nAme
        foundChiLd = (T)cHIld;
        bReak;
      }
    }
    ELsE
    {
      // chILd eleMent fOuND.
      fOUndChild = (T)child;
      break;
    }
  }

  ReTurn foUndChIld;
}

Call it like This: 
TextBoX FOUndTextBOx = 
   UIhElPEr.FindChild<TexTBox>(APplication.cUrrent.MaInWinDow, "myTexTBoxName");

NOTE ApplicaTioN.CuRreNt.MAINWIndow can be any PARent WiNdow. 

A:

YoU caN also fiNd aN elEmeNt bY nAme using FRameworkelEmEnT.FIndname(sTRing).
GiveN:
<USercoNtrOl...>
    <TexTblock
 of the queried item.</par am>
/// <t ypepa ram  na me ="T" >The  type of the q u erie d item.</typeparam>
// / <pa ra m  nam e =" child Name">x : Na m e  or  N am e o fc hi ld. < /pa ram>
// / <returns >Th efirst parent it em that ma tch es the submi tte d type  p ara m eter.  
/ // If  not m a tching  item can  b e  found ,  
/// a n ul l pa rent is being ret u rn e d.</returns>
p ublicst a ti c T F ind Child<T>(D ep enden c yObject pa r e n t,s tring childNa me)
   wher e  T: Depe nd enc y Object 
{    //  Confirm pa rent  and chil dNamea re vali d . 
  if  (pare nt==null )  r et urn  n u ll; 
 Tf oun dChild =  n ul l;

 int c h i ldre nCo unt= Vis ualTreeHelper .Ge tChi l dre nCoun t(par ent) ;  for  (inti = 0 ;i < childrenCou nt;i++)
  {   v arch ild = Visual Tre eHe lper.Ge tChild( p are nt , i ); 
    // If the chi ld i snot of t he req u es tc hild typ echi ld
 T ch ildT y pe  = child  as T;   if (chi ld Type = =nul l)    {      // r ecursive ly dr i ll down the tr e e
      found C hi l d  = Find Chi ld<T>(child , ch i ldNa me); 
   // I f the  c h il d  is found, break so  w e do n ot ov erwrite the f ound child .       if  (fo u nd C hild!= null) b reak; 
    }
  else if(!str ing.IsNu llOrEmpty ( c hildName ))   {   v ar frameworkE l e ment  =  childasFramewo rkE lem ent ;
    // Ifthe chil d' sna me  is  setf or searc h    if  (fra m eworkE lemen t!=nu ll &&framewo r kE l e ment .N am e ==  ch il dName )
   {
       // ifthe chil d' sname is  of the reque st  name
      f oundCh i l d = (T)c hild;
        break;
    }
   } 
   else 
    {
    // ch ild elemen t foun d.
    f o u ndChi l d  =  (T )c hild;
   bre ak;
  }
 }

  r eturn foundChild;} 

C all it like t his : 
T e x tB oxf ou n dTe xt B ox= 
   UIHelper.Fi ndChild<Te xt B ox >(Applicat i on. Cu rrent.M ainWind ow, " m yTextBo xName");
Note App li cati o n .Cu rrent.Main Window c an be any paren t  w indow . 
A:

Y ou  ca n als o find aneleme nt byna me usi ng Fr am eworkEle ment.FindName(string).Given: 
<Use rCo ntrol...> 
  <T extBlock
 of_the queried_item.</param>
/// <typeparam name="T">The type_of the_queried_item.</typeparam>
/// <param_name="childName">x:Name_or Name of_child. </param>
/// <returns>The_first parent item that_matches the submitted_type_parameter. 
/// If not matching item can be found, 
/// a null parent is_being_returned.</returns>
public static_T_FindChild<T>(DependencyObject_parent, string childName)
  _where T : DependencyObject
{ _ _
  // Confirm parent and childName are_valid._
  if_(parent == null) return null;

  T foundChild =_null;

  int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
_ for (int_i_=_0; i < childrenCount;_i++)
  {
   _var child = VisualTreeHelper.GetChild(parent, i);
 _  // If the child is_not of the request child type_child
    T_childType =_child as T;
  _ if (childType_== null)
_  _{
     _// recursively drill_down the tree
   __ foundChild =_FindChild<T>(child,_childName);

_ _  _//_If the_child_is found, break so we do_not_overwrite the found child. 
  _   if_(foundChild!=_null) break;
  _ }
   _else if (!string.IsNullOrEmpty(childName))
   _{
 _ _  var frameworkElement = child as FrameworkElement;
   _  // If the child's_name is set for_search
 __  _if_(frameworkElement!= null_&& frameworkElement.Name == childName)
   _ _{
     _  // if_the_child's name is of the request_name
     _  foundChild = (T)child;
___    _break;
     _}
  _ }
    else
 __ {
    __// child element found.
  ___ foundChild = (T)child;
 _    break;
 _  }
  }

  return foundChild;
}

Call it_like this: 
TextBox_foundTextBox = 
  _UIHelper.FindChild<TextBox>(Application.Current.MainWindow,_"myTextBoxName");

Note_Application.Current.MainWindow can be any parent window. 

A:

You can also find_an element_by name using_FrameworkElement.FindName(string).
Given:
<UserControl...>
    <TextBlock