2015-01-09 95 views
1

我对WPF和XAML非常陌生,我试图创建自定义按钮样式。在XAML中更改边框厚度

我已经有一个按钮模板:

<Style x:Key="RoundButtonTemplate" TargetType="Button"> 
    <Setter Property="Background" Value="LightBlue"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="Button"> 
       <Border x:Name="Test" CornerRadius="5" Background="{TemplateBinding Background}" 
          BorderThickness="1" BorderBrush="Blue"> 
        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"> 
        </ContentPresenter> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

而且豆蔻动画徘徊按钮:

<Style x:Key="Animation" TargetType="Button" BasedOn="{StaticResource RoundButtonTemplate}"> 
    <Style.Triggers> 
     <Trigger Property="IsMouseOver" Value="True"> 
      <Trigger.EnterActions> 
       <BeginStoryboard> 
        <Storyboard> 
         <ThicknessAnimation 
          Storyboard.TargetProperty="BorderThickness" 
          Duration="0:0:0.400" 
          From="1, 1, 1, 1" 
          To="3, 3, 3, 3"/> 
         <DoubleAnimation 
          Storyboard.TargetProperty="Height" 
          Duration="0:0:0.300" 
          From="22" 
          To="25"/> 
         <DoubleAnimation 
          Storyboard.TargetProperty="Width" 
          Duration="0:0:0.300" 
          From="75" 
          To="78"/> 
        </Storyboard> 
       </BeginStoryboard> 
      </Trigger.EnterActions> 
     </Trigger> 
    </Style> 

,一切工作正常,除了ThicknessAnimation。它如何工作?

+0

你试过在厚度动画中加入FillBehavior = HoldEnd – grabthefish

回答

1

ControlTemplate替换BorderThickness="1"BorderThickness="{TemplateBinding BorderThickness}"。您的Style动画控件BorderThickness由于Border使用固定值,因此ControlTemplate内部未使用。

<Style x:Key="RoundButtonTemplate" TargetType="Button"> 
    <Setter Property="Background" Value="LightBlue"/> 
    <Setter Property="BorderThickness" Value="1"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
     <ControlTemplate TargetType="Button"> 
      <Border 
       x:Name="Test" 
       CornerRadius="5" 
       Background="{TemplateBinding Background}" 
       BorderThickness="{TemplateBinding BorderThickness}" 
       BorderBrush="Blue"> 
       <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> 
      </Border> 
     </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

您还需要添加Setter一个像Background默认值。你也可以考虑与BorderBrush做同样的事情。它会让你以后影响BorderBrush而不改变你的控制Template

+0

非常感谢你! :) – Marlon