簡體   English   中英

無法將組合框綁定到數組

[英]Cannot bind combobox to an array

我似乎無法將我的ComboBox綁定到數組。

我有這個ObjectDataProvider

<ObjectDataProvider x:Key="TypeFromEnum" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
    <ObjectDataProvider.MethodParameters>
        <x:Type TypeName="property:Property:PropertyType"/>
    </ObjectDataProvider.MethodParameters>
</ObjectDataProvider>

這個綁定:

<DataTemplate x:Key="TypeCellTemplate">
    <ComboBox ItemsSource="{Binding Path={StaticResource TypeFromEnum}}" SelectedItem="{Binding Path=Type}"/>
</DataTemplate>

但我得到錯誤:

資源類型無效:預期類型為“PropertyPath”,實際類型為“Array”。

當我運行我的程序並嘗試用這個ComboBox打開窗口時,它崩潰了:

PresentationFramework.dll中出現類型'System.Windows.Markup.XamlParseException'的第一次機會異常附加信息:'在'System.Windows.Markup.TypeExtension'上提供值引發異常。 行號'8'和行位置'12'。

如果存在此異常的處理程序,則可以安全地繼續該程序。

ObjectDataProvider設置為Binding Source而不是Path

<ComboBox ItemsSource="{Binding Source={StaticResource TypeFromEnum}}" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM