WPF ComboBox Binding to Enumeration -
i have combo box has itemssource bound enumeration using objectdataprovider, , selecteditem property bound property of businessobject. reason it's binding selecteditem first , itemssource second, therefore overwriting default on businessobject property. ideas why , possibly fix? in advance.
xaml:
<collectionviewsource x:key="units"> <collectionviewsource.source> <objectdataprovider methodname="getnames" objecttype="{x:type sys:enum}"> <objectdataprovider.methodparameters> <x:type typename="bo:unit"/> </objectdataprovider.methodparameters> </objectdataprovider> </collectionviewsource.source> </collectionviewsource> <combobox grid.column="1" horizontalalignment="right" width="80" itemssource="{binding source={staticresource units}}" selecteditem="{binding path=unit}"/>
i tried code , it's working fine don't think order of bindings problem. 1 thing noticed you're using getnames
methodname objectdataprovider
combobox
itemssource collection of strings , not of enum unit
. if intention property unit
should of type string
example
public class namesviewmodel { public namesviewmodel(string unit) { unit = unit; } public string unit { get; set; } }
if change getnames
getvalues
it'll work property of enum type unit
example
public class valuesviewmodel { public valuesviewmodel(unit unit) { unit = unit; } public unit unit { get; set; } }
Comments
Post a Comment