wpf - Two-way binding and a Selector -


setup:

  1. there combobox bound observablecollection.
  2. there car object in ui. color property bound combobox's selecteditem (the binding: <combobox selecteditem="{binding car.color}".../>
  3. 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

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -