Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 如何在ObjectDataProvider中引用另一个类的枚举?_Wpf - Fatal编程技术网

Wpf 如何在ObjectDataProvider中引用另一个类的枚举?

Wpf 如何在ObjectDataProvider中引用另一个类的枚举?,wpf,Wpf,我想将枚举绑定到组合框 下面是包含枚举的类BarcodeModel.cs: 下面是类中的枚举: public enum BarcodeType { AZTEC, CODABAR, CODE128, CODE93, CODE39, DATA_MATRIX, EAN13, EAN8, ITF, MAXICODE, PDF417, QRCODE, RSS14, RSSEXPANDED, UPCA, UPCE, UPC_EAN_EXTENSION } 嗯,在同一项目的另一个目录中,我

我想将枚举绑定到组合框


下面是包含枚举的类
BarcodeModel.cs

下面是类中的枚举:

public enum BarcodeType
        { AZTEC, CODABAR, CODE128, CODE93, CODE39, DATA_MATRIX, EAN13, EAN8, ITF, MAXICODE, PDF417, QRCODE, RSS14, RSSEXPANDED, UPCA, UPCE, UPC_EAN_EXTENSION }
嗯,在同一项目的另一个目录中,我使用
ObjectDataProvider
绑定它:

<Page x:Class="KongGamLung.ToolProperty.BarCodeProperty"
      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:local="clr-namespace:KongGamLung.ToolProperty"
      xmlns:System="clr-namespace:System;assembly=mscorlib"
      xmlns:Model="clr-namespace:KongGamLung.Models"
      mc:Ignorable="d" 
      d:DesignHeight="450" d:DesignWidth="800"
      Title="BarCodeProperty">
    <Page.Resources>
        <ObjectDataProvider x:Key="dataFromEnum" MethodName="GetValues"
                            ObjectType="{x:Type System:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="Model:BarcodeModel.BarcodeType"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
    </Page.Resources>
<ComboBox x:Name="BarcodeTypeCB" ItemsSource="{Binding Source={StaticResource dataFromEnum}}"></ComboBox>
</Page>

运行后,Visual Studio抛出一个XamlParseException错误,该错误无法找到“
{clr命名空间:KongGamLung.Models;assembly=KongGamLung,Version=1.0.0,Culture=neutral,PublicKeyToken=null}BarcodeModel.BarcodeType


如何正确引用枚举?你能帮帮我吗?谢谢。

如果要引用xaml中的嵌套类型,而不是“.”,请使用“+”

<x:Type TypeName="Model:BarcodeModel+BarcodeType"/>


谢谢。它起作用了!然而,我觉得奇怪的是c#使用+但不使用。在这个地方。啊哈。@102425074实际上,嵌套类型的正式类型名使用了“+”。您可以检查嵌套类型的
Type.FullName