样式应用不正确

Style not applied correct

这是我的 Xaml:

<Style TargetType="ComboBox">
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="Foreground" Value="Black" />
    <Setter Property="Margin" Value="5" />
</Style>
<Style TargetType="TextBlock">
    <Setter Property="VerticalAlignment" Value="Center" />
    <Setter Property="Margin" Value="5" />
    <Setter Property="FontSize" Value="20" />
    <Setter Property="FontWeight" Value="Bold" />
    <Setter Property="Foreground" Value="White" />
</Style>
<Style TargetType="TextBox">
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="Margin" Value="5" />
    <Setter Property="Height" Value="35" />
    <Setter Property="FontSize" Value="20" />
</Style>
[...]
<ComboBox SelectedIndex="{Binding Path=BirthdayDay, UpdateSourceTrigger=PropertyChanged, FallbackValue=0}" ItemsSource="{Binding Path=Days, UpdateSourceTrigger=PropertyChanged}" />
<ComboBox SelectedIndex="{Binding Path=BirthdayMonth, UpdateSourceTrigger=PropertyChanged, FallbackValue=0}" ItemsSource="{Binding Path=Months, UpdateSourceTrigger=PropertyChanged}" />
<ComboBox SelectedIndex="{Binding Path=BirthdayYear, UpdateSourceTrigger=PropertyChanged, FallbackValue=0}" ItemsSource="{Binding Path=Years, UpdateSourceTrigger=PropertyChanged}" />

结果很混乱:

它是否以某种方式与 TextBlock Style 相撞? 由于应用了 FontWeight 似乎存在连接?!

注意:

我能看到的唯一 "obvious" 区别是绑定不同:

Day + YearIntegersCollectionMonthstringCollection?!

也许你可以尝试这样的事情:

<Window.Resources>
    <Style x:Key="CommonStyle" TargetType="FrameworkElement">
        <Setter Property="Margin" Value="5" />
    </Style>
    <Style TargetType="ComboBox" BasedOn="{StaticResource CommonStyle}">
    </Style>       
</Window.Resources>

这是由于数据的类型以及您没有定义显示数据的方式所致:ItemTemplate、ItemTemplateSelector 或 StringFormat

如果你加上<Setter Property="ItemStringFormat" Value="{}{0}"></Setter>

所有组合框都将正确显示。

ItemsControl.UpdateSelectionBoxItem 是负责在选择框中显示数据的函数,但我想不通它在提取和显示 Item 的过程中如何将 int 与 String 区别对待。

无论如何,如果我做对了,int 显示为 TextBlocks,String 显示为 TextBox,这就是为什么 int 采用您的样式。