【问题标题】:Glow effect on MouseEnter WPFMouseEnter WPF 上的发光效果
【发布时间】:2013-08-23 09:28:45
【问题描述】:

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

我的效果是:

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

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

【问题讨论】:

  • 如果您向我们展示您已经尝试过的内容,我们可能会为您提供更好的帮助。您尝试了哪些“链接”?为什么他们不为你工作?

标签: c# wpf xaml triggers dropshadow


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    如果您想重用您的效果,您必须捕获 IsMouseOver 触发器并将 Control.Effect 属性设置为您在资源中定义的内容。

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

    为此,您必须将您的效果置于当前页面/窗口/用户控件的资源中

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 2010-10-03
      • 2016-07-15
      • 1970-01-01
      • 2018-05-10
      相关资源
      最近更新 更多