title: Silverlight 4 DataBinding: Binding to ObservableCollection<string> not working anymore
body: <p>Upgrading from SL3 -> SL4. First problem: this throws a parser exception:</p>
  
  <pre><code>&lt;StackPanel Name={Binding} /&gt; (same with x:Name)
  </code></pre>
  
  <p>Collection is <code>ObservableCollection&lt;string&gt;</code>. Worked fine in SL3. So it seems that SL4 doen't allow binding to the Name property. Huh?</p>
  
  <p>So: changed to</p>
  
  <pre><code>&lt;StackPanel Tag={Binding} /&gt;
  </code></pre>
  
  <p>... since I just need to ID the control in code behind. So here's the bug ('cuz this has got to be a bug!):</p>
  
  <p>In this frag, AllAvailableItems is an <code>ObservableCollection&lt;string&gt;</code>:</p>
  
  <pre><code>&lt;ItemsControl Name="lbItems"
                    ItemsSource="{Binding AllAvailableItems}"
                    Height="Auto"
                    Width="Auto"
                    BorderBrush="Transparent"
                    BorderThickness="0"
                    VerticalAlignment="Top"
                    HorizontalAlignment="Left"
                    Margin="12,6,0,0"&gt;
          &lt;ItemsControl.ItemTemplate&gt;
              &lt;DataTemplate&gt;
  
                  &lt;Grid&gt;
                      &lt;Grid.RowDefinitions&gt;
                          &lt;RowDefinition /&gt;
                          &lt;RowDefinition /&gt;
                      &lt;/Grid.RowDefinitions&gt;
  
                      &lt;CheckBox Tag="{Binding}"
                                Checked="ItemChecked_Click"
                                Unchecked="ItemUnchecked_Click"
                                Style="{StaticResource CheckBoxStyle}"
                                Grid.Row="0"&gt;
                          &lt;CheckBox.Content&gt;
                              &lt;TextBlock Text="{Binding}"
                                         Style="{StaticResource FormLJustStyle}" /&gt;
                          &lt;/CheckBox.Content&gt;
                      &lt;/CheckBox&gt;
  
                      &lt;StackPanel Tag="{Binding}"
                                  Orientation="Vertical"
                                  Grid.Row="1"&gt;
                          &lt;configControls:ucLanguage /&gt; &lt;!-- simple user control --&gt;
                      &lt;/StackPanel&gt;
  
                  &lt;/Grid&gt;
  
              &lt;/DataTemplate&gt;
          &lt;/ItemsControl.ItemTemplate&gt;
      &lt;/ItemsControl&gt;
  </code></pre>
  
  <p>In the code behind, I use a recursive function to find the Dependency object with either the Name or Tag property provided:</p>
  
  <pre><code>public static T FindVisualChildByName&lt;T&gt;(DependencyObject parent, string name, DependencyProperty propToUse) where T : DependencyObject
      {
        for (int i = 0; i &lt; VisualTreeHelper.GetChildrenCount(parent); i++)
        {
          var child = VisualTreeHelper.GetChild(parent, i);
          string controlName = child.GetValue(propToUse) as string;
          if (controlName == name)
          {
            return child as T;
          }
          else
          {
            T result = FindVisualChildByName&lt;T&gt;(child, name, propToUse);
            if (result != null)
              return result;
          }
        }
        return null;
      }
  </code></pre>
  
  <p>OK, get this: in the code behind, I can get the control that is ORDERED FIRST in the XAML! In other words, if I put the CheckBox first, I can retrieve the CheckBox, but no StackPanel. And vice-versa. This all worked fine in SL3.</p>
  
  <p>Any help, ideas ... ?</p>
  
  <p>Thanks - Kurt</p>