[英]Get all images that mouse is not over in WPF
我有一个充满大量图像的WPF窗口,我试图找到一种方法来模糊鼠标没有悬停的所有图像。
我正在使用此事件来影响我悬停的图像:
private void Window_MouseMove(object sender, MouseEventArgs e)
{
if (e.OriginalSource is Image)
{
((Image)e.OriginalSource).Effect = new BlurEffect();
}
}
这就是我创建图像的方式
StackPanel imgStkpnl = new StackPanel();
foreach (var urll in Tools.MyGlobals.GoogleImageURLs)
{
var image = new System.Windows.Controls.Image();
var fullFilePath = urll;
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
try
{
bitmap.UriSource = new Uri(fullFilePath, UriKind.Absolute);
bitmap.EndInit();
image.Source = bitmap;
image.Stretch = Stretch.Uniform;
image.HorizontalAlignment = HorizontalAlignment.Left;
imgStkpnl.Children.Add(image);
}
catch { }
}
如果有人知道一种可以影响所有其他图像的方法,那将是非常有帮助的,那么我是一个大新手,所以请放轻松我:)谢谢
使用此XAML,我能够达到您想要的效果:
<Window x:Class="Solutions.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<StackPanel>
<StackPanel.Resources>
<BlurEffect x:Key="BlurEffect"></BlurEffect>
<Style TargetType="Image">
<Setter Property="Effect" Value="{StaticResource BlurEffect}"></Setter>
<Style.Triggers>
<EventTrigger RoutedEvent="MouseEnter" >
<BeginStoryboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Effect">
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Null}"></DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="MouseLeave">
<BeginStoryboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Effect">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource BlurEffect}"></DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</StackPanel.Resources>
<Image Source="cat.jpg" Width="200"></Image>
<Image Source="cat.jpg" Width="200"></Image>
<Image Source="cat.jpg" Width="200"></Image>
</StackPanel>
</Window>
在您的评论之后,要使图像不模糊,只需删除MouseLeave
事件触发器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.