如何在 UWP 中更改 ComboBox 占位符前景

How to change ComboBox placeholder foreground in UWP

我想在我的演示 UWP 应用程序中更改 ComboBox 占位符颜色。所以我尝试创建静态资源:

<UserControl.Resources>
    <Style x:Key="ComboBoxStyle" TargetType="ComboBox">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ComboBox">

                    <ContentControl x:Name="PlaceholderTextContentPresenter"
                                    Content="{TemplateBinding PlaceholderText}" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</UserControl.Resources>

使用:

<ComboBox Grid.Row="1" Foreground="White" HorizontalAlignment="Stretch" Background="Transparent"
              PlaceholderText="Выбор оператора" Style="{StaticResource ComboBoxStyle}">
        <x:String>iPhone 11</x:String>
        <x:String>iPhone 12</x:String>
        <x:String>Xiaomi Red Mi</x:String>
        <x:String>Samsung Galaxy 10</x:String>

        <ComboBox.Resources>
            <Style TargetType="ContentControl">
                <Setter Property="Foreground" Value="White" />
                <Setter Property="FontSize" Value="15" />
            </Style>
        </ComboBox.Resources>
    </ComboBox>

占位符中的前景已正确更改,但 ComboBox 消失了。如何更改 ComboBox 占位符前景?

How to change ComboBox placeholder foreground in UWP

UWP ComboBox 包含 PlaceholderForeground 属性,如果你想改变默认的,你只需要像下面这样给它特定的值。请不要使用 16299 或更高版本中的 属性。

<ComboBox
    Grid.Row="1"
    HorizontalAlignment="Stretch"
    Background="Transparent"
    Foreground="White"
    PlaceholderText="Выбор оператора"
    PlaceholderForeground="DarkBlue">

    <x:String>iPhone 11</x:String>
    <x:String>iPhone 12</x:String>
    <x:String>Xiaomi Red Mi</x:String>
    <x:String>Samsung Galaxy 10</x:String>

</ComboBox>