Silverlight ComboBox and SelectedItem

≡放荡痞女 提交于 2019-12-01 19:17:47

Thanks for your reply. Tried your suggestion already and get the same results. However, I've just had a Homer Simpson moment (Dôh!) and found out that I set the Month before the ComboBox sets it's ItemsSource.

Strange, though, that the RadComboBox does everything correctly. Maybe it retrieves the SelectedItem again when the ItemsSource changes.

EDIT:

OK, I just literally fell off my chair with amazement. Apparently, SL3 still has some bugs that need fixing. Feast your eyes on the following...

This doesn't work:

<ComboBox SelectedItem="{Binding Month, Mode=TwoWay}" ItemsSource="{Binding Months}" />

And this does:

<ComboBox ItemsSource="{Binding Months}" SelectedItem="{Binding Month, Mode=TwoWay}" />

See the tiny difference? As long as I set the ItemsSource before the SelectedItem in the XAML, all is well in the world. Wowee, I never knew XAML was parsed linearly!

How are you setting the Month property? I'm not sure how the ComboBox determines if two items are the same or not, but I could see that it wouldn't work correctly if you pass in "May" rather than Months[4]. As a test, you could try passing in one of the strings from you list to see if that fixes the problem or not.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!