title: Find WPF control by Name
body: <p>I'm after some help finding the best way to refer to controls that have been programmtically built in C#</p>
  
  <p>If I pre include a label in XAML and name it <code>marketInfo</code> then in code I can set the <code>Tag</code> property with something like </p>
  
  <pre><code>marketInfo.Tag = timeNow;
  </code></pre>
  
  <p>However, I'm building controls and assigning each a name using something similar to </p>
  
  <pre><code>System.Windows.Controls.Label lbl = new System.Windows.Controls.Label();
  lbl.Content = market.name + " - " + DateTime.Now.ToLocalTime().ToLongTimeString();
  lbl.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;
  lbl.Height = 40;
  lbl.Name = @"_" + "marketInfo" + countMarket;
  </code></pre>
  
  <p>How do I refer to these controls from another method? I've read a few posts which suggest using the <code>visualtreehelper</code> but this appears to require looping controls to find a particular control. Is there a way to access a control by name to avoid looping?</p>
  
  <p>eg something similar to</p>
  
  <pre><code>//pseudo code
  SomeControl("_marketInfo5").Tag = timeNow;
  </code></pre>
  
  <p>Thank you</p>