Why IsMouseOver is recognized as a WPF style trigger and MouseDown isn't -given that both are valid UIElement properties as seen here-. First trigger works well but second one doesn't even compile.
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="OpacityMask">
<Setter.Value>
<LinearGradientBrush >
<GradientStop Color="Transparent" Offset="0"/>
<GradientStop Color="Black" Offset="0.5"/>
<GradientStop Color="Transparent" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="MouseDown" Value="true">
<Setter Property="OpacityMask">
<Setter.Value>
<LinearGradientBrush>
<GradientStop Color="Black" Offset="0" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
You could use PreviewMouseLeftButtonDown when using Control.Triggers, replacing control with the control item the template is being used in:
You can use MouseDown Event in
Style.Triggers
but you have to use an EventTrigger for that.And remember that
Well, I guess you are mistaking
MouseDown
event for property. There is noIsMouseDown
property but there exist similarIsPressed
property but only for classes inheritingButtonBase
. You should just use event in code-behind or write an attached property if you want to keep your code-behind clean.This is how you do it. Create class:
Then in your style:
And of course add namespace in your XAML file (look at the top):