Data-binding to a ComboBox in WPF/Silverlight isn't always as smooth as one would assume. People have problems here, here and there. The XAML was fairly easy to lay out, I thought. I had:
<ComboBox SelectedItem="{Binding Path=ReferenceType}"
ItemsSource="{Binding Path=ReferenceTypes}" />
It wasn't until I read "I always set the ItemSource before the SelectedItem and all works fine." that I thought I'd try switching my code to:
<ComboBox ItemsSource="{Binding Path=ReferenceTypes}"
SelectedItem="{Binding Path=ReferenceType}" />
This way I define ItemsSource before SelectedItem. However, I never thought for a second that the XAML parser would care. I assumed the parser would figure out that it needs to know about the collection before it cared about what was selected. Obviously, if this were c# code I'd always specify the collection first, but this was XML, what does it care about the order of attributes?
I had broken the first rule of programming, never assume.
No comments:
Post a Comment