WPF SystemColors:TextBox 边框的颜色 [英] WPF SystemColors: color of TextBox border

查看:90
本文介绍了WPF SystemColors:TextBox 边框的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用嵌入的放大镜图标制作搜索文本框.到目前为止,我有以下标记:

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>

但是,我无法在 SystemColors 中找到与标准 TextBox 边框颜色相同的条目.这是默认的蓝色.我在这里真的很傻吗?!?

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?!?

顺便说一句,图像包含在堆栈面板中,因为我也打算在其中放置一个下拉箭头.

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

推荐答案

您可以尝试使用 Microsoft.Windows.Themes.ListBoxChrome 而不是 Border;这就是 TextBox 使用的默认模板:

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>

您应该能够仅使用 ListBoxChrome 而不是 Border 而不是重新模板化 TextBox 以匹配您提供的代码.

You should be able to use just ListBoxChrome instead of Border rather than re-templating TextBox to match the code you presented.

这篇关于WPF SystemColors:TextBox 边框的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆