1) I create and add a combobox to a visual container (usualy Grid) by runtime or it is defined in the XAML page
2) I assign combobox source to the new xmldocument, this loads the content and then document xml data populate the combo items
3) When page init is finished i load page data to setup the form, I set loaded comboboxes to the selecteditems
4) page.show();
this seems to work, but there is like 10% chance that the combobox is loaded, but the selecteditem is blank although the itemsource was populated and selecteditem was set to proper id.
When i trace the code in debug it works on 100% but when i run it without debug it occasionaly forgets to setup the combobox selection.
I have found that this is some sort of bug of WPF combobox, and its possible to "correct" it in the XAML by swaping:
Expand|Select|Wrap|Line Numbers
- <ComboBox ItemsSource="{Binding Countries, Mode=OneWay}" SelectedItem="{Binding SelectedCountry}" DisplayMemberPath="Name" > </ComboBox>
- to:
- <ComboBox SelectedItem="{Binding SelectedCountry}" ItemsSource="{Binding Countries, Mode=OneWay}" DisplayMemberPath="Name" > </ComboBox>
is there any event or trigger that can help to find out, if the combobox has realy finished loading? Also some switch that will forbid combobox to load itemsource in separate thread would be good, as it is unstable in current combobox version.I am using .Net 3.5 SP1
I have tried also this:
SelectedValueId is String property that buffers the id of target record ...
Expand|Select|Wrap|Line Numbers
- combo1.Loaded += delegate { if (SelectedValueId != null) SetSelected(); };