WPF SystemColors:文本框边框的颜色
我正在尝试创建一个带有嵌入式放大镜图标的搜索文本框。 到目前为止,我有以下标记:
<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 边框相同的颜色。 默认情况下,这是一种蓝色。 难道我真的很傻吗?!?
编辑:顺便说一句,图像包含在堆栈面板中,因为我也计划在其中放置一个下拉箭头。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以尝试使用 Microsoft.Windows.Themes.ListBoxChrome 而不是边框; 这就是 TextBox 的默认模板使用的内容:
您应该能够仅使用 ListBoxChrome 而不是 Border,而不是重新模板化 TextBox 以匹配您提供的代码。
You might try using Microsoft.Windows.Themes.ListBoxChrome instead of the Border; that's what the default template for TextBox uses:
You should be able to use just ListBoxChrome instead of Border rather than re-templating TextBox to match the code you presented.
我能够通过以下方式以编程方式获取它:
I was able to get it programatically with:
根据尼古拉斯·阿姆斯特朗的回答,该解决方案对我有用:
Based on Nicholas Armstrong's answer, that solution is working for me:
对于任何正在寻找画笔列表及其颜色在不同主题/操作系统下的外观的人:
最初发布:http://blogs.msdn.com/b/wpf/archive/2010/11/30/systemcolors-reference.aspx。
To anyone that is looking for a list of Brushes and what their colors will look like with different themes/OS:
Originally posted: http://blogs.msdn.com/b/wpf/archive/2010/11/30/systemcolors-reference.aspx.
这看起来很黑客,但我通过创建一个文本框(可能已折叠)并绑定到其边框画笔而获得了最好的运气。
It seems hackish, but I've had the best luck by creating a textbox (perhaps collapsed) and binding to its border brush.