我有一个Button模板,其中包含一个网格边框。
禁用该按钮后,边框仍然显示为活动状态。
是否有一种方法可以在按钮被禁用时淡出边框并在按钮启用时显示边框?
<Button.Template>
<ControlTemplate>
<Border BorderThickness="{Binding Path=BorderThickness, RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType=Button}}" BorderBrush="{Binding Path=BorderBrush, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}"
Opacity="{Binding Path=BorderBrush, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}">
Buttons with drop menu are mine, the others are typical buttons
答案 0 :(得分:0)
你需要一个触发器。在禁用时,我将边框设为绿色。
<Button Content="test" Name="test" Height="20">
<Button.Template>
<ControlTemplate>
<Border BorderThickness="{Binding Path=BorderThickness, RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType=Button}}" BorderBrush="{Binding Path=BorderBrush, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}"
Opacity="{Binding Path=BorderBrush, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}">
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="BorderBrush" Value="Green" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>