我正在尝试使用嵌入式放大镜图标创建搜索TextBox。到目前为止,我有以下标记:
<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边框颜色相同的条目。默认情况下,这是一种蓝色。我在这里真的很蠢吗?!?
编辑:顺便说一下,图片包含在堆叠面板中,因为我打算在那里放一个下拉箭头。答案 0 :(得分:4)
您可以尝试使用Microsoft.Windows.Themes.ListBoxChrome而不是Border;这就是TextBox使用的默认模板:
<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以匹配您提供的代码。
答案 1 :(得分:4)
任何正在寻找画笔列表的人以及不同主题/操作系统的颜色会是什么样的
我会看这里:http://blogs.msdn.com/b/wpf/archive/2010/11/30/systemcolors-reference.aspx
答案 2 :(得分:3)
根据Nicholas Armstrong的回答,该解决方案对我有用:
<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 :(得分:2)
我能够以编程方式获得它:
TextBox.BorderBrush = SystemColors.ControlDarkBrush;
答案 4 :(得分:1)
看起来似乎是hackish,但我通过创建一个文本框(可能已折叠)并绑定到其边框画笔获得了最好的运气。