2016-11-08 2 views
1

Ich habe eine Kontrolle Gewohnheit in WPF und ich brauche eine comboBox darauf eine Enumeration zu binden, ich schrieb,bindet Enum Combobox auf EIGENE KONTROLL

auf der Web-Suche fand ich, dass dies der Weg zu gehen:

<ObjectDataProvider 
    MethodName="GetDict" 
    ObjectType="{x:Type App:EnumDescriptionValueDict}" 
    x:Key="EnumDescriptionDict"> 
    <ObjectDataProvider.MethodParameters> 
    <x:Type TypeName="App:Transmission"></x:Type> 
    </ObjectDataProvider.MethodParameters> 
</ObjectDataProvider> 

<ComboBox 
     ItemsSource="{Binding Source={StaticResource EnumDescriptionDict}}" 
     DisplayMemberPath="Key" 
     SelectedValuePath="Value"/> 

aber meine Kontrolle XAML

<UserControl x:Class="WpfControlFoo.UserControl1" 
      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" 
      mc:Ignorable="d" Width="799" Height="107"> 

so finde ich keinen Ort, um die Object XAML

0 einfügen

Vielen Dank für die Vorschläge :)

+1

Mit dem Bereich es in definieren –

+1

Evk

Antwort

2

Sie können Ressourcen wie in den Kommentaren vorgeschlagen verwenden.

voll XAML.

<UserControl x:Class="WpfControlFoo.UserControl1" 
      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:App="myNamespaceWhereTheEnumIsLocated" 
      mc:Ignorable="d" Width="799" Height="107"> 
<UserControl.Resources> 
<ObjectDataProvider 
    MethodName="GetDict" 
    ObjectType="{x:Type App:EnumDescriptionValueDict}" 
    x:Key="EnumDescriptionDict"> 
    <ObjectDataProvider.MethodParameters> 
    <x:Type TypeName="App:Transmission"></x:Type> 
    </ObjectDataProvider.MethodParameters> 
</ObjectDataProvider> 
</UserControl.Resources> 
<ComboBox 
     ItemsSource="{Binding Source={StaticResource EnumDescriptionDict}}" 
     DisplayMemberPath="Key" 
     SelectedValuePath="Value"/> 
</UserControl> 
+0

Und nur hinzufügen zu @Mat Antwort, 'App:' ist der Namespace, in dem sich die öffentliche Enumeration befindet. –

+0

@LupuSilviu thx, um dies zu verdeutlichen. Hinzugefügt zu meinem Beitrag – Mat

Verwandte Themen