我有两个ComboBoxes
。一个绑定到枚举值列表,而另一个绑定到自定义类对象列表并具有DisplayMemberPath
属性集。
对枚举值的ComboBox
绑定应用了隐式TextBlock
样式,而ComboBox
使用该DisplayMemberPath
属性的 则没有。
使用Snoop我可以验证两者ComboBoxes
都使用完全相同的控件集(a<ContentPresenter>
包含 a <TextBlock>
)呈现,但是没有集合中的 a 包含TextBlock
5而带有set 的控件不包含。ComboBox
DisplayMemberPath
Margin
DisplayMemberPath
<Grid.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="5" />
</Style>
</Grid.Resources>
<ComboBox Grid.Row="0" Grid.Column="1"
ItemsSource="{Binding EnumCollection}"
SelectedItem="{Binding SelectedEnum}" />
<ComboBox Grid.Column="1" Grid.Row="2"
ItemsSource="{Binding SomeCollection}"
SelectedItem="{Binding SelectedItem}"
DisplayMemberPath="Name" />
为什么是这样?我能做些什么来阻止枚举ComboBox
继承隐式TextBlock
样式?