title: WPF - FindName Returns null when it should not
body: <p>FindName is broken for me :(</p>
  
  <p>The object I am looking for is there.  I have proof.</p>
  
  <p>Here is the scenario:</p>
  
  <pre><code>ToggleButton button = (ToggleButton)sender;
  Popup popup = (Popup)button.FindName("popSelectIteration");
  </code></pre>
  
  <p><code>popup</code> is null but not always.  Just sometimes.  But even when it is set to null the child I am looking for is there.</p>
  
  <p>I put a break point in when it was null and grabbed these two screenshots.</p>
  
  <p>The is where FindName is returning null for "popSelectIteration".</p>
  
  <p>But if you dig into the watch, you see that the child is there.</p>
  
  <p>So what am I missing?  Why does FindName not find it?  As you can see from the screen shot this is not a timing issue (the FindName watch is null but the direct path is fine).</p>
  
  <p>Is there a better way to find a control?</p>
  
  <p><em>Side Note:</em> If you are intersted in the XAML for the toggle button in question it can be found in this question: <a href="https://stackoverflow.com/questions/2285196/wpf-frameworkelement-enumerate-all-decendents">WPF - FrameworkElement - Enumerate all decendents?</a>.</p>
  
  <hr>
  
  <p><strong>Update</strong>: I did some digging to see why this fails some times and other times it works.  I have an animation that calls <code>NameScope.SetNameScope((DependencyObject)form, new NameScope());</code> (Full method code <a href="http://gist.github.com/307383" rel="noreferrer">here</a>).  Right after that call the FindName starts to fail.</p>
  
  <p>I don't really understand that call.  I think I copied and pasted the code.  Anyway, I commented it out. But I would love know why this is failing.</p>