开发者

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

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 pa开发者_开发百科ssing 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜