我花了很多时间查看将枚举绑定(bind)到列表框的代码,我在以下情况下做得很好:
- 与 XAML 在同一命名空间内的枚举
枚举位于以 Windows.etc 开头的 namespace 中.... 但是,我有一个枚举包含在 Microsoft.Research.Kinect.Nui 的命名空间命名空间中:
<Window.Resources> <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="Joints"> <ObjectDataProvider.MethodParameters> <x:Type TypeName="JointID" /> </ObjectDataProvider.MethodParameters> </ObjectDataProvider> </Window.Resources>
在我设置方法参数类型的那一行,我得到一个错误
Type 'JointID' not found
我知道这与设置 clr-namespace 路径有关:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:mic="clr-namespace:Microsoft;assembly=Microsoft.Research.Kinect"
(管理API的程序集是Microsoft.Research.Kinect.dll) 但是当我这样做时,我得到一个错误:
Undefined CLR namespace. The 'clr-namespace' URI refers to a namespace 'Microsoft' that is not included in the assembly.
怎么办?
最佳答案
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:mic="clr-namespace:Microsoft;assembly=Microsoft.Research.Kinect"
xmlns:local="clr-namespace:YOUR NAMESPACE" >
<Window.Resources>
<ObjectDataProvider MethodName="GetValues"
ObjectType="{x:Type sys:Enum}"
x:Key="Joints">
<ObjectDataProvider.MethodParameters>
<x:Type Type="{x:Type local:JointID" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
</Window>
尝试绑定(bind)类型。您必须在顶部添加您的命名空间,并且枚举必须是公开的。那么我想你应该可以引用它。
关于c# - 找不到来自绑定(bind)到 ListBox 的导入命名空间的枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6455728/