2

我想在 WPF (XAML) 中创建一个边框,该边框使用当前 Windows 主题(XP、Areo、Classic、Modern UI)中的颜色。

我已经尝试使用SystemColors类中的一些画笔,但边框看起来与 a 的默认边框不同TextBox

有什么办法可以得到真正的边界刷?

4

1 回答 1

3

下面给出的是 WPF 用于TextBox控件的默认样式:

  <Style TargetType="{x:Type TextBox}">
    <Setter Property="SnapsToDevicePixels"
            Value="True" />
    <Setter Property="OverridesDefaultStyle"
            Value="True" />
    <Setter Property="KeyboardNavigation.TabNavigation"
            Value="None" />
    <Setter Property="FocusVisualStyle"
            Value="{x:Null}" />
    <Setter Property="MinWidth"
            Value="120" />
    <Setter Property="MinHeight"
            Value="20" />
    <Setter Property="AllowDrop"
            Value="true" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type TextBoxBase}">
          <Border Name="Border"
                  CornerRadius="2"
                  Padding="2"
                  BorderThickness="1">
            <Border.Background>
              <SolidColorBrush Color="{DynamicResource ControlLightColor}" />
            </Border.Background>
            <Border.BorderBrush>
              <SolidColorBrush Color="{DynamicResource BorderMediumColor}" />
            </Border.BorderBrush>
            <VisualStateManager.VisualStateGroups>
              <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal" />
                <VisualState x:Name="Disabled">
                  <Storyboard>
                    <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                                  Storyboard.TargetProperty="(Panel.Background).
                      (SolidColorBrush.Color)">
                      <EasingColorKeyFrame KeyTime="0"
                                           Value="{StaticResource DisabledControlLightColor}" />
                    </ColorAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="ReadOnly">
                  <Storyboard>
                    <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                                  Storyboard.TargetProperty="(Panel.Background).
                      (SolidColorBrush.Color)">
                      <EasingColorKeyFrame KeyTime="0"
                                           Value="{StaticResource DisabledControlDarkColor}" />
                    </ColorAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="MouseOver" />
              </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <ScrollViewer Margin="0"
                          x:Name="PART_ContentHost" />
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
于 2013-03-08T17:04:46.667 回答