c# - ObservableDictionary binding to combobox display value(MVVM) -
i have problem databinding. have wpf (mvvm) user control project. there comboboxes
, labels
. every combobox
binds observabledictionary<int,string>
. problem need show string part of dictionary on combobox
.
also, combobox itemsource
changes depends on selected @ previous combobox
. , mvvm pattern. there model , view model.
i tried setting displaypath
etc. couldn't show strings on combos. seeing [0, sample]
, [1,yes]
.
<combobox horizontalalignment="left" margin="250,15,0,0" verticalalignment="top" width="120" name="cbxerisim" selectionchanged="cbxerisim_selectionchanged" itemssource="{binding derisimkodu}" /> <combobox horizontalalignment="left" margin="250,45,0,0" verticalalignment="top" width="120" name="cbxteklifdurum" selectionchanged="cbxteklifdurum_selectionchanged" itemssource="{binding dteklifdurumu}"/> <combobox horizontalalignment="left" margin="250,75,0,0" verticalalignment="top" width="120" name="cbxteklifsonuc" selectionchanged="cbxteklifsonuc_selectionchanged" itemssource="{binding dteklifsonuc}"/>
you need set following properties (i'm assuming observabledictionary
inherits idictionary<tkey, tvalue>
):
selectedvaluepath="key" displaymemberpath="value"
i have tested using this implementation of observabledictionary<tkey, tvalue>
in view:
<combobox width="35" selectedvaluepath="key" displaymemberpath="value" itemssource ="{binding firstdictionary}"/>
and view model:
public class viewmodel { private observabledictionary<int, string> _firstdictionary; public viewmodel() { _firstdictionary = new observabledictionary<int, string>() { new keyvaluepair<int, string>(1, "a"), new keyvaluepair<int, string>(2, "b"), new keyvaluepair<int, string>(3, "c") }; } public observabledictionary<int, string> firstdictionary { { return _firstdictionary; } set { _firstdictionary = value; } } }
Comments
Post a Comment