我有一个Button
由ControlTemplate
.
它包含一个Canvas
包含一个Path
。我想Path.Opacity
根据鼠标状态添加更改:
- 默认 - 0.5
- 鼠标悬停,未按下 - 1.0
- 鼠标悬停,按下 - 0.5
第一种情况只需设置本地值Path.Opacity
to0.5
并添加一个Trigger
for IsMouseOver
:
<Button x:Class="ImagingShop.Panosphere.Controls.PathButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="100" d:DesignWidth="100"
Name="pathButton">
<Button.Template>
<ControlTemplate>
<Canvas Background="Transparent" Width="{TemplateBinding Width}" Height="{TemplateBinding Width}">
<Canvas.Style>
<Style TargetType="Canvas">
<Setter Property="Path.Opacity" Value="0.5"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Path.Opacity" Value="1.0"/>
</Trigger>
</Style.Triggers>
</Style>
</Canvas.Style>
<Path Data="{Binding ElementName=pathButton, Path=PathData}" Stretch="Uniform" Fill="#FFFFFFFF" Width="{TemplateBinding Width}" Height="{TemplateBinding Width}"/>
</Canvas>
</ControlTemplate>
</Button.Template>
<Grid>
</Grid>
</Button>
但是,第三种情况不起作用。我添加了以下触发器:
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True"/>
<Condition Property="Button.IsPressed" Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="Path.Opacity" Value="0.75"/>
</MultiTrigger>
所以这应该设置Path.Opacity
为0.75
鼠标悬停在按钮上并按下按钮。
我坚持这一点,因为不透明度改为0.5
而不是0.75
!触发器似乎适用,但没有按预期工作......