I'm seeing a strange issue when binding to ComboBox where the display value sometimes shows up blank. The case is repeatable however and happens the second time a dialog opened from another parent form. If the parent form is closed and reopened then the first time it's child dialog is opened the contained WPF ComboBox shows the display property correctly. If I then close the dialog and relaunch it again from the same parent form the ComboBox shows no display value even though I can verify the same bound properties are being hit in my ViewModel.
<ComboBox ItemsSource="{Binding AvailableVehicles}"
SelectedValuePath="Value"
SelectedValue="{Binding SelectedVehicle, Mode=TwoWay}"
DisplayValuePath="Value.Model" />
To explain the data structure for my ViewModel it's basically just a class that exposes an AvailableVehicles collection which houses a objects which are similar to the Nullable<> type in that it wraps a Vehicle object and exposes it through a Value property. Each Vehicle then has a Model and Cost property.
I've been troubleshooting this now for longer than a day and I've pretty much ruled out everything but this being a bug in the ComboBox itself. So at this point I'm hoping for a reasonable workaround but if somebody can actually help point out a flaw in my code that would be great too.
Notes:
- I haven't been able to get this problem to reproduce in a more simple single Window WPF example.
- The WinForms interop scenario where I have an MDI parent Form and child forms that house WPF UserControls in case that may be relevant.
- If I set IsAsync to True on either the ItemsSource or the SelectedValue bindings the problem no longer occurs.
- If I make DisplayValuePath instead into a ItemsTemplate and in the binding within the defined DataTemplate I place a converter, I've noticed that the value passed in is null instead of the expected value.