1 回答
TA贡献1802条经验 获得超6个赞
一种解决方案是为边框的边距设置动画。此外,我必须将触发器从 Style.Triggers 移动到 ControlTemplate.Triggers 以访问作为目标的边框。
<Style TargetType="Button"
x:Key='Circular'>
<!--Set to true to not get any properties from the themes.-->
<Setter Property="OverridesDefaultStyle"
Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Border x:Name='_bottom'
CornerRadius='5'
BorderBrush="Black"
BorderThickness="0,0,0,2">
<Rectangle Fill="Gray" />
</Border>
<Border x:Name='_top'
CornerRadius='5'
BorderBrush="Black"
BorderThickness="0,0,0,2"
Margin='0,0,0,10'>
<Grid>
<Rectangle Fill="LightGray" />
<ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
</Border>
</Grid>
<ControlTemplate.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding='{Binding RelativeSource={RelativeSource Self}, Path=IsPressed}'
Value='True' />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ThicknessAnimation Storyboard.TargetProperty="Margin"
Storyboard.TargetName="_top"
Duration="0:0:0.1"
From="0,0,0,10"
To="0,10,0,0" />
<ThicknessAnimation Storyboard.TargetProperty="Margin"
Storyboard.TargetName="_bottom"
Duration="0:0:0.1"
From="0,0,0,0"
To="0,10,0,0" />
</Storyboard>
</BeginStoryboard>
</MultiDataTrigger.EnterActions>
<MultiDataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<ThicknessAnimation Storyboard.TargetProperty="Margin"
Storyboard.TargetName="_top"
Duration="0:0:0.1"
From="0,10,0,0"
To="0,0,0,10" />
<ThicknessAnimation Storyboard.TargetProperty="Margin"
Storyboard.TargetName="_bottom"
Duration="0:0:0.1"
From="0,10,0,0"
To="0,0,0,0" />
</Storyboard>
</BeginStoryboard>
</MultiDataTrigger.ExitActions>
</MultiDataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
- 1 回答
- 0 关注
- 167 浏览
添加回答
举报