title: How to iterate controls in WPF
body: <p>I have a simple XAML file with a grid in it and textboxes. But when using my code it does not find the textboxes by iteration.</p>
  
  <p>VB.Net:</p>
  
  <pre><code>Dim ctl As FrameworkElement = Me.MainWindow
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>Dim ChildrenCount As Integer = VisualTreeHelper.GetChildrenCount(ctl)
  'ChildrenCount is always zero
  For i As Integer = 0 To ChildrenCount - 1
      Dim Child As FrameworkElement = VisualTreeHelper.GetChild(ctl, i)
      Call SetLanguageToControls(Keyword, cLanguage, Child)
  Next
  </code></pre>
  
  <p>XAML:</p>
  
  <pre><code>&lt;Window x:Class="MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="MainWindow"  Icon="/OUTPUT%20-%20Histogram;component/Sprectrum.ico"&gt;
      &lt;Grid x:Name="LayoutRoot"&gt;
          &lt;Grid x:Name="SpectrumContent" Margin="8" Height="120" Width="320"&gt;
              &lt;Rectangle Grid.Row="0" Grid.Column="1" Opacity="0.5"&gt;
                  &lt;Rectangle.Fill&gt;
                      &lt;LinearGradientBrush StartPoint="0,0" EndPoint="1,0"&gt;
                          &lt;GradientStop Offset="0" Color="Black" /&gt;
                          &lt;GradientStop Offset="1" Color="White" /&gt;
                      &lt;/LinearGradientBrush&gt;
                  &lt;/Rectangle.Fill&gt;
              &lt;/Rectangle&gt;
          &lt;TextBlock x:Name="txtRedMin" Text="|Red:" Foreground="Red" FontWeight="Bold" /&gt;
          &lt;TextBlock x:Name="txtRedMinValue" Text="000%" /&gt;
          &lt;/Grid&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p><strong>EDIT</strong>
  Problem is solved. I used the code while managing language in my plugins. But MainWindow1.Loaded was not called. If Window is not loaded, this code does not work. If Window is loaded, this code works.</p>