WPF SystemColors: TextBox border color

I am trying to search a TextBox with a built-in magnifying glass icon. So far I have the following markup:

<Border DockPanel.Dock="Bottom" Margin="2,4,0,4" BorderThickness="1" SnapsToDevicePixels="True" BorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"> <DockPanel> <StackPanel Orientation="Horizontal" DockPanel.Dock="Right"> <Image Source="/Resources/search-13x13.png" Width="13"/> </StackPanel> <TextBox Name="searchTextBox" DockPanel.Dock="Bottom" BorderThickness="0" Text="{Binding FilterText, UpdateSourceTrigger=PropertyChanged}"/> </DockPanel> </Border> 

However, I cannot find an entry in SystemColors that will give me the same color as the standard TextBox border. By default, it is blue. Am I really stupid here?!?

EDIT: btw, the image is contained in the stack panel because I also plan to place the down arrow.

+6
source share
5 answers

You can try using Microsoft.Windows.Themes.ListBoxChrome instead of Border; that the default template for the TextBox is used:

 <ControlTemplate TargetType="TextBoxBase" xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"> <mwt:ListBoxChrome Name="Bd" SnapsToDevicePixels="True"> <ScrollViewer Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" /> </mwt:ListBoxChrome> <ControlTemplate.Triggers> <Trigger Property="UIElement.IsEnabled" Value="False"> <Setter TargetName="Bd" Property="Panel.Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" /> <Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> 

You should be able to use only ListBoxChrome instead of Border, and not modify the TextBox templates according to the code you submitted.

+4
source

For anyone looking for a list of brushes and how their colors will look with different themes / OS

I would look here: http://blogs.msdn.com/b/wpf/archive/2010/11/30/systemcolors-reference.aspx

+3
source

Based on Nicholas Armstrong's answer, this solution works for me:

 <Style TargetType="{x:Type local:CustomTextBox}" BasedOn="{StaticResource {x:Type TextBox}}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:CustomTextBox}"> <mwt:ListBoxChrome x:Name="Bd" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" RenderFocused="{TemplateBinding IsKeyboardFocusWithin}" RenderMouseOver="{TemplateBinding IsMouseOver}"> <ScrollViewer x:Name="PART_ContentHost" /> </mwt:ListBoxChrome> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> 
+3
source

I managed to get it programmatically using

 TextBox.BorderBrush = SystemColors.ControlDarkBrush; 
+2
source

This seems to be hacks, but I got lucky by creating a text box (possibly crashed) and binding it to the border.

+1
source

All Articles