Posts

Showing posts from October, 2017

Custom ComboBox control to defer current selection

I had this weird requirement in my project where: When I change the selection, new value should be sent to ViewModel, but the selection should not be changed until Success response comes back from a custom device attached to the application. i.e. If failure arrives then, combobox value will remain unchanged, and if success arrives then only ComboBox reflects the new value. Requirement was very unusual and that was not the functionality a built in combo-box supposed to do. So, I had to create a custom control with few hacks to make it work. Following is the code: public class ExtendedComboBox : ComboBox, ICommandSource { private bool _valueUpdatedFromUI; private int _previousIndex; private bool _dropDownClosed; private object _newlySelectedItem; #region DP /// <summary> /// Sends new value to ViewModel property /// </summary> public object DeferredSelectedItem { get { return (object)GetValue(DeferredSelectedItemProperty); }