Databinding to object properties breaks when setting null to object in Silverlight

StackOverflow https://stackoverflow.com/questions/5007903

  •  14-11-2019
  •  | 
  •  

문제

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?

올바른 솔루션이 없습니다

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top