【发布时间】:2016-12-15 13:41:53
【问题描述】:
基于此答案https://stackoverflow.com/a/33109026/426386 我向我的 ComboBox 集合添加了一个空项目。由于我的 Combobox 定义了 SelectedValue 和 SelectedValuePath,我会遇到 Bindingerrors:
<UserControl.Resources>
<ObjectDataProvider
x:Key="CardTypeProvider"
MethodName="GetLocalizedEnumValues"
ObjectType="{x:Type base:Localize}">
<ObjectDataProvider.MethodParameters>
<x:Type
TypeName="base:CardTypes" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</UserControl.Resources>
<ComboBox
DisplayMemberPath="Value"
SelectedValue="{Binding GroupByCardType, UpdateSourceTrigger=PropertyChanged}"
SelectedValuePath="Key">
<ComboBox.Resources>
<CollectionViewSource
x:Key="Items"
Source="{Binding Source={StaticResource CardTypeProvider}}" />
</ComboBox.Resources>
<ComboBox.ItemsSource>
<CompositeCollection>
<TextBlock />
<CollectionContainer
Collection="{Binding Source={StaticResource Items}}" />
</CompositeCollection>
</ComboBox.ItemsSource>
</ComboBox>
ObjectDataProvider 返回以下类型:
Dictionary<Enum, string>
为了避免绑定错误,我想实例化 KeyValuePair<Enum, string> 而不是 TextBlock。有可能吗?
【问题讨论】: