Glow Effect on MouseEnter WPF

I am new to WPF (C #). I need to make a glow effect around image control using triggers . How can I make the glow effect on the mouse-enter event? I want to use my answer in my style.

My effect:

 <DropShadowEffect x:Key="MyEffect" ShadowDepth="0" Color="Blue" Opacity="1" BlurRadius="20"/> 

I see a lot of links, but they do not work.

+4
source share
2 answers

To add flicker to Image , you need to set Effect to DropShadowEffect when IsMouseOver=True , something like this:

 <Image Source="/WpfApplication1;component/myimage.png"> <Image.Style> <Style TargetType="{x:Type Image}"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Effect"> <Setter.Value> <DropShadowEffect ShadowDepth="0" Color="Blue" Opacity="1" BlurRadius="20"/> </Setter.Value> </Setter> </Trigger> </Style.Triggers> </Style> </Image.Style> </Image> 
+11
source

If you want to reuse the effect, you must grab the IsMouseOver trigger and set the Control.Effect property for what you defined in your resources.

 <Button Width="100" Content="Hello Glow" > <Button.Style> <Style> <Style.Triggers> <Trigger Property="Button.IsMouseOver" Value="True"> <Setter Property="Button.Effect" Value="{StaticResource MyEffect}" /> </Trigger> </Style.Triggers> </Style> </Button.Style> </Button> 

to do this, you must put the effect in the resources of the current page / window / user control

 <Window.Resources> <DropShadowEffect x:Key="MyEffect" ShadowDepth="0" Color="Blue" Opacity="1" BlurRadius="20"/> </Window.Resources> 
+7
source

Source: https://habr.com/ru/post/1498562/


All Articles