English 中文(简体)
WPF 客体:文本Box边界的颜色
原标题:
  • 时间:2009-06-05 12:27:06
  •  标签:

我用一个嵌入式放大镜进行搜索。 页: 1

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

然而,我发现,在系统采集器中,我可以发现与标准文本Box边界相同的色。 这是一种不履约的蓝色。 我真的 st不 st!

EDIT:btw, 图像被装在一 st中,因为I m计划在那里放下 drop的arrow子。

问题回答

您可尝试使用微软。 Windows. Themes.ListBoxChrome und the Border; that s what theault model for TextBox use:

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

你们应当能够只使用清单BoxChrome,而不是使用边界,而不是重新铺设案文Box,以便与你提出的法典保持一致。

我能够以方案方式与以下各方接触:

TextBox.BorderBrush = SystemColors.ControlDarkBrush;

根据尼古拉斯·阿斯特里格的答复,这一解决办法对我来说是可行的:

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

To anyone that is looking for a list of Brushes and what their colors will look like with different themes/OS: https://i.stack.imgur.com/E2VBv.png

最初张贴:http://blogs.msdn.com/b/wpf/archive/

这似乎 ha笑了,但我早上打了最好的灯塔,建立了一个文本箱(可能崩溃),对边界rush有约束力。





相关问题
热门标签