I want to apply the following changes when the Button
is pressed.
<Button>
<Button.Effect>
<DropShadowEffect BlurRadius="10" ShadowDepth="5"/>
</Button.Effect>
</Button>
What about handling the Click
event for the Button
?
<Button Content="Click me!" Click="Button_Click_1" Margin="10" />
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
button.Effect = new System.Windows.Media.Effects.DropShadowEffect()
{
BlurRadius = 10,
ShadowDepth = 5
};
}
Or use a Style
that binds to the IsPressed
property if you want to display the shadow only while the Button is being pressed:
<Button Content="Button">
<Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect BlurRadius="10" ShadowDepth="5"/>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
Or use a ToggleButton
and set the Effect
property based on its IsChecked
property:
<ToggleButton>
<ToggleButton.Style>
<Style TargetType="ToggleButton">
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect BlurRadius="10" ShadowDepth="5"/>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</ToggleButton.Style>
</ToggleButton>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With