我在我的全局字典中将TextBlock
的前景设置为白色,并且此样式也适用于Combobox
,这也使得组合框选项无法读取。我无法找到一种简单的方式来为0123或980以上的windows 8或更高版本设置背景。所以我决定现在可以采用默认的Combobox
风格,但我仍然无法找到一个简单的解决方案。我试图设置的Combobox
的,风格TextBlock
Combobox.Resources
和风格ComboBoxItem
没有运气下。最简单的方法来设置组合框的前景色
这将是理想的,如果我可以设置组合框的背景为黑色,而无需复制整个Combobox
的控制模板。如果不是的话,如果我可以在我的字典中使用Combobox
的前景,那么这将是最好的,但我愿意接受解决方案。
编辑:最低例子包括
Dictionary1.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1">
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="WhiteSmoke"/>
</Style>
</ResourceDictionary>
的App.xaml:
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
mainwindow.xaml
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525"
Closing="Window_Closing">
<Grid>
<ComboBox Text="test" Height="50" Width="100" Foreground="Black">
<ComboBox.Resources>
<Style TargetType="ComboBoxItem">
<Style.Setters>
<Setter Property="Foreground" Value="Black"/>
</Style.Setters>
</Style>
<Style TargetType="TextBlock">
<Style.Setters>
<Setter Property="Foreground" Value="Black"/>
</Style.Setters>
</Style>
</ComboBox.Resources>
<ComboBoxItem>test1</ComboBoxItem>
<ComboBoxItem>test2</ComboBoxItem>
</ComboBox>
</Grid>
</Window>
注意,所有的foregroun d =黑色作品。我使用Windows 10
你可以请你发布你的ComboBox和TextBlock模板吗? –
@DaxPandhi我没有模板他们(使用默认的),只有一种样式适用于TextBlock,它是 –
Steve
我刚才遇到了同样的问题。我会找到我用来修复它的代码并在几分钟内发布。 –