c# - bind enum to Combobox On CUSTOM CONTROL -
i have custom control in wpf , need bind combobox on enum wrote,
searching on web found way go:
<objectdataprovider methodname="getdict" objecttype="{x:type app:enumdescriptionvaluedict}" x:key="enumdescriptiondict"> <objectdataprovider.methodparameters> <x:type typename="app:transmission"></x:type> </objectdataprovider.methodparameters> </objectdataprovider> <combobox itemssource="{binding source={staticresource enumdescriptiondict}}" displaymemberpath="key" selectedvaluepath="value"/>
but control xaml
<usercontrol x:class="wpfcontrolfoo.usercontrol1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:ignorable="d" width="799" height="107">
so don't find place insert objectdataprovider xaml
thanks suggestions :)
you can use resources suggested in comments.
full xaml:
<usercontrol x:class="wpfcontrolfoo.usercontrol1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:app="mynamespacewheretheenumislocated" mc:ignorable="d" width="799" height="107"> <usercontrol.resources> <objectdataprovider methodname="getdict" objecttype="{x:type app:enumdescriptionvaluedict}" x:key="enumdescriptiondict"> <objectdataprovider.methodparameters> <x:type typename="app:transmission"></x:type> </objectdataprovider.methodparameters> </objectdataprovider> </usercontrol.resources> <combobox itemssource="{binding source={staticresource enumdescriptiondict}}" displaymemberpath="key" selectedvaluepath="value"/> </usercontrol>
Comments
Post a Comment