这是我的问题。 我有一个包含组合框的 WPF 应用程序。 我想将此组合框绑定(bind)到其他项目的枚举。
在我的应用程序(AdapterApp)中,我尝试了以下操作:
xmlns:System="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:Adapter"
<Window.Resources>
<ObjectDataProvider x:Key="dataFromEnum" MethodName="GetValues"
ObjectType="{x:Type System:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="local:MyEnum"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
<ComboBox ItemsSource="{Binding Source={StaticResource dataFromEnum}}" HorizontalAlignment="Left" Margin="117,113,0,0" VerticalAlignment="Top" Width="150"/>
在我的其他项目中:
namespace Adapter
{
public enum MyEnum
{
Lent = 0,
Rapide
};
}
我有这个错误:
The name "MyEnum" does not exist in the namespace "clr-namespace:Adapter".
我做错了什么?
最佳答案
您应该添加对其他项目的引用,然后将 otherProjectNamespace
命名空间定义为 xmlns:otherProjectNamespace="clr-namespace:Adapter; assembly=MyOtherProject"
。
如果您未指定程序集,编译器会尝试在当前程序集(即应用程序的程序集)中查找 Adapter
命名空间。
关于c# - 如何在 WPF 中将组合框绑定(bind)到其他项目的枚举?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24284048/