tags:

views:

1820

answers:

2

I am trying to make a search TextBox with an embedded magnifying glass icon. I have the following markup so far:

    <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 can't find the entry in SystemColors which will give me the same color as the standard TextBox border. This is a blueish color by default. Am I being really stupid here?!?

EDIT: btw, the image is contained in a stackpanel because I'm planning to put a dropdown arrow in there as well.

+1  A: 

You might try using Microsoft.Windows.Themes.ListBoxChrome instead of the Border; that's what the default template for TextBox uses:

<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 just ListBoxChrome instead of Border rather than re-templating TextBox to match the code you presented.

Nicholas Armstrong
Thanks for the suggestion but that doesn't seem to work. I get no border.
Groky
You may have to re-template TextBox (or your custom TextBox) to include ListBoxChrome; it is working for me when I used that code to change the control template on a default TextBox.
Nicholas Armstrong
+2  A: 

I was able to get it programatically with:

TextBox.BorderBrush = SystemColors.ControlDarkBrush;
baron
This worked a treat, cheers!
TabbyCool