Question

Pseudocode sample:

<UserControl>
   <ComboBox SelectedValuePath="Id" SelectedValue="{Binding CurrentObject.Id, Mode=TwoWay}" ItemSource="{Binding Groups}"/>
   <ComboBox SelectedValuePath="Name" SelectedValue="{Binding CurrentObject.Status, Mode=TwoWay}" ItemSource="{Binding Statuses}"/>
</UserControl>

I'm passing object of <MyObject> type to this usercontrol, modifying it and then saving. After doing this, I'm reseting state with CurrentObject = null. On second pass, those comboboxes have no selected values, though there is actual data. How can I fix it?

No correct solution

OTHER TIPS

You always have to set the data source for data binding to some object, otherwise databinding will not work. Binding to null will never work.
Do not set currentobject to null, but maybe set the CurrentObject.Id to 0 and reset it to the final value as soon as you know (e.g. on the second pass). When your object implements INotifyPropertyChanged, the values on the user interface will be updated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top