我有两个ComboBoxes。一个绑定到枚举值列表,而另一个绑定到自定义类对象列表并具有DisplayMemberPath属性集。
对枚举值的ComboBox绑定应用了隐式TextBlock样式,而ComboBox使用该DisplayMemberPath属性的 则没有。
使用Snoop我可以验证两者ComboBoxes都使用完全相同的控件集(a<ContentPresenter>包含 a <TextBlock>)呈现,但是没有集合中的 a 包含TextBlock5而带有set 的控件不包含。ComboBoxDisplayMemberPathMarginDisplayMemberPath
<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样式?