title: Looping through StackPanel children in WPF
body: <p>I have a <code>StackPanel</code> that is full of controls, I am trying to loop through the elements and get their Names, but it seems that I need to cast each element to its type in order to access its <code>Name</code> property.</p>
  
  <p>But what if I have a lot of different types in the StackPanel and I just want to get the elements name?</p>
  
  <p>Is there a better way to do that?</p>
  
  <p>Here is what I've tried:</p>
  
  <pre><code>foreach (object child in tab.Children)
  {
      UnregisterName(child.Name);
  }
  </code></pre>