在 WP8.1 中显示 ComboBox 的 PlaceholderText 颜色

Show PlaceholderText Color of ComboBox in WP8.1

我想问你我应该怎么做才能在白色背景网格上显示 ComboBox 的占位符文本。

 <Grid Background="White">
    <ComboBox Name="CityCombobox"   BorderThickness="0"  Grid.Column="1" PlaceholderText="Select Item">
        <ComboBoxItem>Chandigarh</ComboBoxItem>
        <ComboBoxItem>Delhi</ComboBoxItem>
        <ComboBoxItem>Sirsa</ComboBoxItem>
    </ComboBox>
</Grid>

很明显,因为您将背景设为白色,而占位符颜色也是白色(当 phone 背景色为黑色时),您看不到占位符。您可以做的就是不将背景颜色设置为白色,因为 Windows Phone 的默认值会将其设置为黑色或白色,这将确保占位符颜色可见。

否则您将需要覆盖占位符的颜色。您可以通过两种方式执行此操作。

  1. 全局:这将覆盖整个应用程序中占位符的所有颜色。您可以在 app.xaml
  2. 中这样做

<ResourceDictionary.ThemeDictionaries> <ResourceDictionary x:Key="Default"> <SolidColorBrush x:Key="TextBoxPlaceholderTextThemeBrush" Color="#ff000000" /> </ResourceDictionary> </ResourceDictionary.ThemeDictionaries>

  1. 覆盖对象的样式。当您在 xaml 中添加元素时。在设计器中右键单击它。在那里你可以选择复制样式。将其放在文档中。找到 TextBoxPlaceholderTextThemeBrush 并赋予它你的价值。然后给你的元素 xaml 这种特殊的风格

试试这个

            <ComboBox SelectionChanged="City_SelectionChanged" Name="CityCombobox" RequestedTheme="Light" BorderThickness="0" Tapped="CitySelection_Tapped" Grid.Column="1" PlaceholderText="Select City">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding City.city}" Style="{StaticResource PageTextStyle}"/>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>

此处请求的主题为即使在白色背景下也显示占位符文本的控件设置浅色主题。希望对你有帮助。