title: WPF - Getting a collection of all controls for a given type on a Page?
body: <p>I'm trying to get a list of all controls of a given type on a given Page, but I'm encountering problems.  It seems that it's possible that the VisualTreeHelper only returns controls that have been loaded?  I tried turning off Virtualization, but that didn't seem to help.  Can anyone think of another way to get all the control or perhaps force a load of the UI so that the following method does work?</p>
  
  <p>I borrowed this from MSDN:</p>
  
  <pre><code> public static IEnumerable&lt;T&gt; FindVisualChildren&lt;T&gt;(DependencyObject depObj) where T : DependencyObject
          {
              if (depObj != null)
              {
                  for (int i = 0; i &lt; VisualTreeHelper.GetChildrenCount(depObj); i++)
                  {
                      DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
  
                      if (child != null &amp;&amp; child is T)
                      {
                          yield return (T)child;
                      }
  
                      foreach (T childOfChild in FindVisualChildren&lt;T&gt;(child))
                      {
                          yield return childOfChild;
                      }
                  }
              }
          }
  </code></pre>