I spent well over an hour on Friday with this one and gave up. I spent almost another hour today working on this. I almost gave up, but when I’m in learn-mode like I am with Silverlight, these types of issues can really teach you a lot if you see them through. I had a ComboBox with bindings on it’s ItemSource and SelectedItem like so:
<ComboBox Name="ComboBoxControl" Style="{StaticResource ComboBoxStyle}"
SelectedItem="{Binding Path=SelectedOption, Mode=TwoWay}"
ItemsSource="{Binding Path=Options}"
IsEnabled="{Binding Path=IsReadOnly}"
Foreground="{StaticResource SemiDarkTextBrush}"
Height="22" Width="150" Grid.Column="1" Margin="30,0,10,0" HorizontalAlignment="Stretch" >
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock
Foreground="{StaticResource SemiDarkTextBrush}"
Text="{Binding Path=Label, Mode=OneWay}"
TextWrapping="Wrap" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
I put breakpoints in my model’s SelectedOption property and I could see Silverlight calling it. So, I knew there were no hard binding errors. The bindings were working, except… they weren’t. The ComboBox always showed up with no selected item. I kept plugging away, and by accident I discovered the order of the binding occurrences matter. Changing the markup to define the ItemsSource binding before the SelectedItem binding solved the problem. Like so:
<ComboBox Name="ComboBoxControl" Style="{StaticResource ComboBoxStyle}"
ItemsSource="{Binding Path=Options}"
SelectedItem="{Binding Path=SelectedOption, Mode=TwoWay}"
IsEnabled="{Binding Path=IsReadOnly}"
Foreground="{StaticResource SemiDarkTextBrush}"
Height="22" Width="150" Grid.Column="1" Margin="30,0,10,0" HorizontalAlignment="Stretch" >
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock
Foreground="{StaticResource SemiDarkTextBrush}"
Text="{Binding Path=Label, Mode=OneWay}"
TextWrapping="Wrap" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Wow, that’s pretty nasty. I’m lucky stumbled on the solution. I consider this a bug.
Hope this helps someone else out there