mvvm - Binding ComboBox selected Item to a property of the View Model -
hi trying bind combobox selected item property in view model setter take value , perform other logic. combobox working correctly pulling items off observablecollection systems have been unable bind selecteditem serial property. selected item not getting string value of combobox. eveything else ok datacontext assigned view in code behind. ideas viewmodel:
public class cablingrequests : observablecollection<cablingrequest> { public observablecollection<cablingrequest> pendingrequests { get; set; } public observablecollection<cablingrequest> processedrequests { get; set; } public observablecollection<cablingrequest> systems { get; set; } public observablecollection<cablingrequest> selectedsystemconfiguration { get; set; } private string _serial; public string serial { { return _serial; } set { if (_serial == value) return; _serial = value; getselectedsystemconfiguration(_serial); } }
and xaml code of combobox:
<combobox x:name="comboboxserial" itemssource="{binding path=systems}" displaymemberpath="serialnumber" selectedvalue="{binding path=serial, mode=twoway}" issynchronizedwithcurrentitem="true" minwidth="150" />
your combobox bound collection of cablingrequest
, should either bind selecteditem
instance of cablingrequest
, or if want serial number, should set selectedvaluepath
'serialnumber' property of cablingrequest
type.
see difference between selecteditem, selectedvalue , selectedvaluepath more information.
Comments
Post a Comment