WPF组合框的结合在不同的命名空间枚举 [英] wpf binding combobox to enum in different namespace

查看:209
本文介绍了WPF组合框的结合在不同的命名空间枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图绑定一个XAML组合框,这样它的列表项是System.IO.Ports.Parity枚举的成员。

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

我发现很多数据绑定枚举的例子,但似乎如果枚举是在不同的命名空间(如System.IO.Ports)这些不工作。

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).

现在我有:

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

但我得到的错误类型引用无法找到名为'System.IO.Ports.Parity公益型。

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

任何想法如何做到这一点?

Any ideas how to accomplish this?

推荐答案

添加类似

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

再修改&LT; X:型号/&GT;

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

应该使其工作。

这篇关于WPF组合框的结合在不同的命名空间枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆