c# - MouseEnter WPF 上的发光效果

标签 c# wpf xaml triggers dropshadow

我是 WPF(c#) 的新手。我需要使用 triggers 在图像控制周围制作发光效果。如何在 mouse-enter 事件上制作发光效果? 我想按照我的风格使用你的答案。

我的效果是:

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

我看到很多链接,但它们不起作用。

最佳答案

要向 Image 控件添加光晕,您需要在 IsMouseOver=True 时将 Effect 设置为您的 DropShadowEffect,像这样:

<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>

关于c# - MouseEnter WPF 上的发光效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18399401/

相关文章:

c# - 在 Angular 6 和 ASP.net 中启用 CORS

c# - 为什么我得到 "Cannot resolve symbol ' CreatePerOwinContext'”?

wpf - 哪些原因会阻止应用显式和隐式样式?

c# - 如何从 Windows Phone 应用程序发送带有代理地址的 HttpWebRequest

c# - 使用初始化 block 不好吗

c# - XAML 和 C# 代码背后的 UI 区别

wpf - "{StaticResource {dxgt:GridRowThemeKey ResourceKey=RowStyle}}"的隐藏代码是什么

c# - 为索引属性创建模板

c# - 设置 xamarin toolbaritems 的背景颜色

wpf - 创建一个具有水平拉伸(stretch)的三个相等列的网格