我在WPF自定義的控制,我需要一個ComboBox它綁定到一個枚舉我寫的,綁定枚舉組合框上的自定義控制
搜索,我發現,這是要走的路在網絡上:
<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"/>
但我的控制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">
,所以我不覺得插入ObjectDataProvider的 XAML
0的地方感謝您的建議:)
使用區域來定義它 –