我有一個在App.xaml中定義的默認TextBlock樣式,這似乎也影響ComboBox項目的文本顏色。現在,我該如何顯式設置在我的主窗口中定義的組合框的文本顏色? (我想保持默認的風格,但有組合框的文本顏色,比如藍色,而不是紅色...)覆蓋組合框中默認的TextBlock樣式
的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"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="Red" />
</Style>
</Application.Resources>
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"
Title="MainWindow">
<Grid>
<ComboBox Name="comboBox1" SelectedIndex="0" HorizontalAlignment="Left" VerticalAlignment="Top">
<ComboBoxItem Content = "Item1"/>
<ComboBoxItem Content = "Item2"/>
<ComboBoxItem Content = "Item3"/>
</ComboBox>
</Grid>
件
事情我已經嘗試:
- 集Combobox.Foreground
- 集TextElement.Foreground
- 集TextBlock.Foreground
- 定義在ComboBox.Resources另一個隱含的TextBlock風格
- 定義Grid.Resources中的另一個隱式TextBlock樣式
- 在Window.Resources中定義另一個隱式TextBlock樣式
我嘗試在組合框資源中添加另一個TextBlock樣式。不幸的是,它沒有任何效果。 – 2012-01-27 15:08:20
我編輯的問題,包括我已經嘗試過的一些事情 – 2012-01-27 15:12:11
@ErenErsonmez看到我編輯的答案。我沒有注意到你在'Application.Resources'中有自己的樣式,而沒有'Window.Resources' – Rachel 2012-01-27 15:24:50