Reputation: 3677
This should be simple, therefore it is something I am missing. I need to change the background color of the a button during the click only. So if a user click the button for 2 days, then the color changes during that two day period. Once the user is done clicking it returns to the normal color. Figured this would solve my issue:
<Style x:Key="MyButtonStyle" TargetType="Button">
<Setter Property="Background" Value="Red"/>
<Setter Property="Button.Effect">
<Setter.Value>
<DropShadowEffect Color="Black" Direction="320" ShadowDepth="3" BlurRadius="5" Opacity="0.5" />
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Button.Background" Value="Purple" />
<Setter Property="Button.Effect">
<Setter.Value>
<DropShadowEffect Color="Black" Direction="320" ShadowDepth="0" BlurRadius="0" Opacity="0" />
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
Now I know the IsPressed
does work as the DropShadowEffect
work correctly during the press. However the color does not change. The only reason I could think why is that IsMouseOver
is taking priority over IsPressed
. If this is the case how can I get the two events to "work together?"
Now before people start linking me to this;
WPF changing button background on click or this Change Button Background color on EventTrigger in WPF or this Change Button Background color on EventTrigger in WPF
Yes those change the color of the button but irrespective on the users click time. As stated above I only want it effected during the actual user's click, like the DropShadowEffect
Upvotes: 2
Views: 6015
Reputation: 3677
ahhh, I was right! The problem was in fact that IsMouseOver
and IsPressed
where not getting along! Here is the fix;
<Style x:Key="NewButton" TargetType="Button">
<Setter Property="Background" Value="Red"/>
<Setter Property="Button.Effect">
<Setter.Value>
<DropShadowEffect Color="Black" Direction="320" ShadowDepth="3" BlurRadius="5" Opacity="0.5" />
</Setter.Value>
</Setter>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsPressed" Value="False" />
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="Green" />
</MultiTrigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Button.Background" Value="Purple" />
<Setter Property="Button.Effect">
<Setter.Value>
<DropShadowEffect Color="Black" Direction="320" ShadowDepth="0" BlurRadius="0" Opacity="0" />
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
Upvotes: 3