【问题标题】:How to change ComboBox placeholder foreground in UWP如何在 UWP 中更改 ComboBox 占位符前景
【发布时间】:2021-02-15 23:21:05
【问题描述】:

我想在我的演示 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 占位符前景?

【问题讨论】:

    标签: xaml uwp combobox uwp-xaml


    【解决方案1】:

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

    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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-20
      • 1970-01-01
      • 2022-01-16
      • 2013-10-04
      • 1970-01-01
      相关资源
      最近更新 更多