wpf - Two-way binding and a Selector -
setup:
- there combobox bound observablecollection.
- there car object in ui. color property bound combobox's selecteditem (the binding:
<combobox selecteditem="{binding car.color}".../> - the color list can change in database , should refreshed sometimes.
the problem:
when observablecollection<mycolor> refreshed (== means sends reset inside collectionchanged event) car's color property set first item in collection => list refreshed => combobox reloads collection , sets selected item first 1 in collection => car's color changed same first item (because of two-way binding) => problem
so in short - how can avoid this? how can tell on reload take selected item right away binding?
you can remove binding while collection changes:
var binding = combobox.getbindingexpression(combobox.selecteditemproperty).parentbinding; combobox.clearvalue(combobox.selecteditemproperty); changingdata.clear(); // <rebuild> combobox.setbinding(combobox.selecteditemproperty, binding);
Comments
Post a Comment