2014-05-12 68 views
1

我注意到MahApps Metro提供的SquareButtonStyle沒有1像素邊框。我期待相處這種風格的東西線(適用於Visual Studio的按鈕樣式)覆蓋MahApps Metro中的SqaureButton風格

enter image description here

而且Metro風格是這樣的:

enter image description here

我已經看過通過按鈕樣式的XAML,但它顯示該按鈕的邊框厚度爲1.如果其他按鈕具有1px邊框,如上面的按鈕,這怎麼可能?我將如何覆蓋這個按鈕,就像我已經顯示的關閉按鈕。

這裏是到button.xaml(編輯鏈接)鏈接:https://github.com/MahApps/MahApps.Metro/blob/master/MahApps.Metro/Styles/Controls.Buttons.xaml

這裏是SquareButton XAML:

<Style x:Key="SquareButtonStyle" 
     TargetType="{x:Type Button}"> 
    <Setter Property="MinHeight" 
      Value="25" /> 
    <Setter Property="FontFamily" 
      Value="{DynamicResource DefaultFont}" /> 
    <Setter Property="FontWeight" 
      Value="SemiBold" /> 
    <Setter Property="Background" 
      Value="{DynamicResource WhiteBrush}" /> 
    <Setter Property="BorderBrush" 
      Value="{DynamicResource BlackBrush}" /> 
    <Setter Property="Foreground" 
      Value="{DynamicResource TextBrush}" /> 
    <Setter Property="Padding" 
      Value="5,6" /> 
    <Setter Property="BorderThickness" 
      Value="1" /> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type Button}"> 
       <Grid> 
        <VisualStateManager.VisualStateGroups> 
         <VisualStateGroup x:Name="CommonStates"> 
          <VisualState x:Name="Normal" /> 
          <VisualState x:Name="MouseOver"> 
           <Storyboard> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" 
                    Storyboard.TargetName="MouseOverBorder"> 
             <EasingDoubleKeyFrame KeyTime="0" 
                   Value="1" /> 
            </DoubleAnimationUsingKeyFrames> 
            <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderThickness)" 
                     Storyboard.TargetName="MouseOverBorder"> 
             <EasingThicknessKeyFrame KeyTime="0" 
                   Value="2" /> 
            </ThicknessAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="Pressed"> 
           <Storyboard> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" 
                    Storyboard.TargetName="PressedBorder"> 
             <EasingDoubleKeyFrame KeyTime="0" 
                   Value="1" /> 
            </DoubleAnimationUsingKeyFrames> 
            <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderThickness)" 
                     Storyboard.TargetName="MouseOverBorder"> 
             <EasingThicknessKeyFrame KeyTime="0" 
                   Value="0" /> 
            </ThicknessAnimationUsingKeyFrames> 
            <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderThickness)" 
                     Storyboard.TargetName="PressedBorder"> 
             <EasingThicknessKeyFrame KeyTime="0" 
                   Value="2" /> 
            </ThicknessAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="Disabled"> 
           <Storyboard> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" 
                    Storyboard.TargetName="DisabledVisualElement"> 
             <SplineDoubleKeyFrame KeyTime="0" 
                   Value="0.7" /> 
            </DoubleAnimationUsingKeyFrames> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" 
                    Storyboard.TargetName="contentPresenter"> 
             <EasingDoubleKeyFrame KeyTime="0" 
                   Value="0.3" /> 
            </DoubleAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
         </VisualStateGroup> 
         <VisualStateGroup x:Name="FocusStates"> 
          <VisualState x:Name="Focused" /> 
          <VisualState x:Name="Unfocused" /> 
         </VisualStateGroup> 
         <VisualStateGroup x:Name="ValidationStates"> 
          <VisualState x:Name="Valid" /> 
          <VisualState x:Name="InvalidFocused" /> 
          <VisualState x:Name="InvalidUnfocused" /> 
         </VisualStateGroup> 
        </VisualStateManager.VisualStateGroups> 
        <Border x:Name="Background" 
          BorderBrush="{DynamicResource BlackBrush}" 
          BorderThickness="2" 
          Background="{TemplateBinding Background}" /> 
        <Rectangle x:Name="DisabledVisualElement" 
           Fill="{DynamicResource ControlsDisabledBrush}" 
           IsHitTestVisible="false" 
           Opacity="0" /> 
        <Border x:Name="MouseOverBorder" 
          Background="{DynamicResource GrayBrush8}" 
          Opacity="0" /> 
        <Border x:Name="PressedBorder" 
          Background="{DynamicResource BlackBrush}" 
          Opacity="0" 
          BorderBrush="{DynamicResource BlackBrush}" /> 
        <ContentPresenter x:Name="contentPresenter" 
             ContentTemplate="{TemplateBinding ContentTemplate}" 
             Content="{TemplateBinding Content, Converter={StaticResource ToLowerConverter}}" 
             HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
             Margin="{TemplateBinding Padding}" 
             RecognizesAccessKey="True" 
             VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
             OpacityMask="{x:Null}" /> 
       </Grid> 

       <ControlTemplate.Triggers> 
        <Trigger Property="IsMouseOver" 
          Value="True"> 
         <Setter Property="Foreground" 
           Value="{DynamicResource BlackBrush}" /> 
        </Trigger> 
        <Trigger Property="IsPressed" 
          Value="true"> 
         <Setter Property="Foreground" 
           Value="{DynamicResource WhiteBrush}" /> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

回答

3

我認爲它這一塊 <Border x:Name="Background" BorderBrush="{DynamicResource BlackBrush}" BorderThickness="2" Background="{TemplateBinding Background}" />

+0

好吧,我會嘗試改變的帽子。爲什麼它會在頂部顯示borderThickness =「1」? –

+0

如果您想要使用您還需要設置否則這個邊框將始終有其默認值 –

1

不要忘記將按鈕的文字內容演示者設置爲:

<ContentPresenter x:Name="contentPresenter" 
    ContentTemplate="{TemplateBinding ContentTemplate}" 
    Content="{TemplateBinding Content}" 
    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
    Margin="{TemplateBinding Padding}" 
    RecognizesAccessKey="True" 
    VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
    OpacityMask="{x:Null}" /> 

如果您不希望文本爲小寫。這裏是我沒有地雷:

https://github.com/joazlazer/ModdingStudio/blob/master/ModdingStudio/ModdingStudio/Themes/Buttons.xaml

這使我這個:http://i.imgur.com/5ZWa2ln.png