Reputation: 31
There was already a post on this but appeared there was no resolution. Perhaps it was before the SelectionBrush
property was exposed for the TextBox
.
I have a Style
for the TextBox
in my resources that works correctly (the selected text is not the default System color but a color I have chosen). I would assume the TextBox
component of my custom ComboBox
template would use that TextBox
Style
but the selected text in the ComboBox
TextBox
is still blue.
Since I know I can control the selected text color of a TextBox
, how do I control it in my ComboBox
ControlTemplate
? I have image and code exaqmples but this forum will not let me post them since this is my first time.
Upvotes: 1
Views: 1077
Reputation: 2673
You can use the below code, it solve your problem
<Window.Resources>
<Style TargetType="{x:Type TextBox}">
<Setter Property="SelectionBrush" Value="Yellow"></Setter>
</Style>
</Window.Resources>
<Grid>
<TextBox Text="ramesh test" Margin="67,12,184,240" />
<ComboBox ItemsSource="{Binding}" Name="testCombo" Margin="67,48,184,204">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBox Text="mytext" Width="100" Height="50" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
Upvotes: 1
Reputation: 43636
You can override the ComboBox HighlightBrushKey
color
<ComboBox x:Name="MyCombo" ItemsSource="{Binding Items}" Margin="0,0,0,148">
<ComboBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Yellow" />
</ComboBox.Resources>
</ComboBox>
Upvotes: 0