To avoid further frustration and the additional code required for syncing the model and widget, we will handle this discrepancy internally either with change in the widget behavior or with a custom value binding. So yeah the Model is god, but again MVVM..view should reflect the model, and the model should reflect the view yeah?Shouldn't have to worry about niggly little details like this, we just want it to work as one would expect. although i'm using angular, i constantly hit this problem all the time where what the dropdownlist shows as being selected is out of sync w/ ngmodel. lol With all these changes, now the widget can match the model state and we will not be forced to update the model automatically on load, which is "dead wrong".because the Selected Item State just stay the same item and using MVVM it remaining the View Model side in darkness. Since every items control has internal property called selected Item, and the selected Item stay as it was because the label got is value from outside, and if we select same as last selected item it not called to observers and raise the Selection Change Event , So, if we understand the problem we probably think about refresh the selected item after every selection Changed, to do this using MVVM lets try use Triggers Action of System windows Interactivity.
In general, the Drop Down List widget should always have a selected item - if there is no value, then the first one will be selected.If you would like to bind the widget to an empty value than usage of an option Label option is obligatory.Sometimes this showed as, you could select something go, leave the page and return and the selection would be cleared, or even worse, it works on some visits to a page but not others when you hadn’t changed the selection. it looks like Selected Item uses Reference Equals to find the item in the collection.So this code has problems because it recreates the collection AND its items on every get, In this case, during the bind of the Selected Item it is checked against an empty collection, and as a result, the selected Item ends up being set to null. One thing that helps is that if you switch your binding to Mode=One Way then the binding will display correctly in the Combo Box (but obviously won’t update). Recently, I received a question from one of my twitter tribemates on using the Combo Box in WPF with objects, and it centered around the difference between the Selected Value, Selected Value Path, and Selected Item properties.
This post will go through the differences, and how they are used, and also do a little review on databinding in WPF.
Based on info from this Stack Overflow question, I tried the following.
In the setter, you prompt the user and attempt to cancel the selection by discarding the new selected value. The View Model will have the values that you desire, but the UI will look like it applied the changes. Doing this on a separate Dispatcher operation is tolerable, but having to make it look like the value actually took and then undoing it seems like it crosses the line of sanity.
It sort of makes sense once you get it working, but this is definitely not intuitive.
I’ve had problems using UWP Combo Boxes, the symptoms being that even by Binding the Selected Item, nothing would be selected in the Combo Box when it was displayed. Basically if you re-create your collection items then it is impossible for selected item to be found in it, i.e.
I updated the provided js Fiddle demo to demonstrate the suggested approach.