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

问题描述 投票:0回答:1

我想将枚举绑定到ComboBox。 这是包含枚举的类BarcodeModel.csenter image description here

这是课堂上的枚举:

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-namespace:KongGamLung.Models;assembly=KongGamLung, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null}BarcodeModel.BarcodeType

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

wpf
1个回答
1
投票

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

<x:Type TypeName="Model:BarcodeModel+BarcodeType"/>
© www.soinside.com 2019 - 2024. All rights reserved.