2013-03-26 88 views
3

爲什麼Button的邊框厚度不變?更改wpf中的按鈕邊框厚度?

如果我將邊框厚度更改爲1或100,則無關緊要。一樣的。我想改變它使用風格,而不是自定義模板

<Window x:Class="GUI.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 

    Title="MainWindow" Height="350" Width="525"> 
<Window.Resources> 
    <Style x:Key="newYellowButton" TargetType="{x:Type Button}"> 
     <Setter Property="Width" Value="100"/> 
     <Setter Property="Height" Value="100"/> 
     <Setter Property="Background"> 
      <Setter.Value> 
       <RadialGradientBrush Center="0.5,0.5" GradientOrigin="0.5,0.5" RadiusX="0.5" RadiusY="0.5" SpreadMethod="Pad" ColorInterpolationMode="SRgbLinearInterpolation"> 
        <GradientStop Color="#FFEEEE3B" Offset="0.5" /> 
        <GradientStop Color="#FFF0E49A" Offset="1" /> 
       </RadialGradientBrush> 
      </Setter.Value> 
     </Setter> 
     <Setter Property="BorderThickness" Value="9"/> 
     <Setter Property="BorderBrush" Value="Blue" /> 
     <Setter Property="Padding" Value="-4"/> 
    </Style> 
</Window.Resources> 
<Grid> 
    <Button Style="{StaticResource newYellowButton}" Content="Ok"/> 
</Grid> 

+0

正常工作對我來說,你已經發布的代碼。還嘗試更改樣式中的BorderThickness,並按預期輸出。 – Viv 2013-03-26 11:46:13

回答

2

您可以通過改變Button's ControlTemplate做到這一點。將這些樣式,畫筆和......複製到您的資源字典中,然後更改所需的值。

要更改邊框厚度找到下面的代碼,讓你想改變:

... 
<Border 
     x:Name="Border" 
     CornerRadius="2" 
     BorderThickness="1"        //CHANGE THIS VALUE 
     Background="{StaticResource NormalBrush}" 
     BorderBrush="{StaticResource NormalBorderBrush}"> 
     <ContentPresenter 
     Margin="2" 
     HorizontalAlignment="Center" 
     VerticalAlignment="Center" 
     RecognizesAccessKey="True"/> 
</Border> 
... 
+0

我只是想知道這是否可以實現沒有模板,只是風格。 – 2013-03-26 11:54:13

+0

其實如果你按照鏈接,你會發現,這是一個簡單的風格。我編輯了我的帖子。 – 2013-03-26 11:55:48

+0

非常感謝您的回答! – 2013-03-26 12:00:06