2013-03-08 49 views
2

我想在使用當前Windows主題(XP,Areo,Classic,Modern UI)的顏色的WPF(XAML)中創建邊框。創建使用Windows主題的邊框

我已經嘗試使用SystemColors類中的一些畫筆,但邊框看起來與TextBox的默認邊框不同。

有什麼辦法可以得到真正的邊界刷?

+0

這個位置http://archive.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=wpfsamples&DownloadId= 7812包含默認WPF控件的模板,並且應該爲您提供適當的畫筆以供使用。 – Stewbob 2013-03-08 17:01:32

回答

3

下面給出的是爲TextBox控制使用WPF的默認樣式:

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