Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wpf binding combobox to enum in different namespace

I'm trying to bind a XAML ComboBox so that its list items are the members of the System.IO.Ports.Parity enum.

I've found plenty of examples of databinding enums, but it seems these don't work if the enum is in a different namespace (like System.IO.Ports).

Right now I have:

<ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="parityValues">
        <ObjectDataProvider.MethodParameters>
            <x:Type TypeName="System.IO.Ports.Parity" />
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>

But I get the error "Type reference cannot find public type named 'System.IO.Ports.Parity'."

Any ideas how to accomplish this?

like image 608
Klay Avatar asked Dec 10 '25 15:12

Klay


1 Answers

Adding something like

xmlns:sysioports="clr-namespace:System.IO.Ports;assembly=System"

and then changing the <x:Type /> line to

<x:Type TypeName="sysioports:Parity" />

Should make it work.

like image 186
toad Avatar answered Dec 12 '25 12:12

toad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!