简体   繁体   English

如何在wpf中使鼠标悬停事件的图像增长x%?

[英]How can I make an image grow x % on mouseover event in wpf?

I have a ListBox containing a set of images in a C# WPF application. 我有一个ListBox包含C#WPF应用程序中的一组图像。 When the image enters the image area, that is, on the MouseEnter event, I want the image to grow approx 10 %. 当图像进入图像区域时,即在MouseEnter事件上,我希望图像增长大约10%。 This is to notify the user that the mouse pointer is now on a new "clickable" image. 这是为了通知用户鼠标指针现在位于新的“可点击”图像上。 Do anyone know how I can accomplish this? 有谁知道我怎么能做到这一点?

Thanx in advance! Thanx提前!

I can only sketch it very rough, but this could be achieved with a trigger on the IsMouseOverProperty that changes the ScaleX & Y properties of a ScaleTransform already placed on the element. 我只能粗略地绘制它,但这可以通过IsMouseOverProperty上的触发器来实现,该触发器改变已经放置在元素上的ScaleTransform的ScaleX和Y属性。

EDIT : Looking at Chris' post, this could then work: 编辑 :看看克里斯的帖子,这可能会起作用:

<Style.Triggers>
  <Trigger Property="IsMouseOver" Value="True">
    <Setter Property="RenderTransform">
      <Setter.Value>
          <ScaleTransform ScaleX="1.5" ScaleY="1.5" />
      </Setter.Value>
    </Setter>
  </Trigger>
</Style.Triggers>

This post on Learn WPF shows how to add a glowing effect on the mouse over: 这篇关于学习WPF的文章展示了如何在鼠标上添加发光效果:

  <Style.Triggers>
    <Trigger Property="IsMouseOver" Value="True">
      <Setter Property="BitmapEffect">
        <Setter.Value>
          <OuterGlowBitmapEffect GlowColor="Red" GlowSize="4"/>
        </Setter.Value>
      </Setter>
    </Trigger>
  </Style.Triggers>

Just replace the "BitmapEffect" setter with a "ScaleTransform" one and you should be good to go. 只需用“ScaleTransform”替换“BitmapEffect”设置器就可以了。 This post on Ryan Cromwell's blog shows how to do it on the button click. Ryan Cromwell博客的这篇文章展示了如何在按钮点击上执行此操作。 It demonstrates the important point which is to set the render transform centre to be the centre of the image so that the scaling is uniform in all directions and not just from the top left. 它演示了重要的一点,即将渲染变换中心设置为图像的中心,以便缩放在所有方向上均匀,而不仅仅是从左上角开始。

register these two events: 注册这两个事件:

private void image1_MouseEnter(object sender, MouseEventArgs e)
{
    Image img = ((Image)sender);
    img.Height = img.ActualHeight * 1.1;

}

private void image1_MouseLeave(object sender, MouseEventArgs e)
{
    Image img = ((Image)sender);
    img.Height /= 1.1;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM