我想使用EventHandler
MouseEnter和MouseLeave来更改图像的OpasityMask
,该图像将在运行时在不同页面上生成。关键是我需要访问发件人才能更改类ViewModel 上OpacityMask
命令的属性MouseHover
。
this.WendActivated(d =>
{
d(this.BindCommand(ViewModel,
vm => vm.MouseHover,
v => v.myImage,
myImage.Events().MouseEnter));
});
private void Image_MouseEnterExecute(object sender, MouseEventArgs e)
{
PlaySound("mouse_hover.mp3");
var image = sender as Image;
image.OpacityMask = new SolidColorBrush { Opacity = 1, Color = Colors.Black };
}
我不知道如何实施事件来更改OpacityMask
public ReactiveCommand MouseHover => image_MouseEnter;
public ObservedChange<object, object> ImageBrush => imageBrush;
public ViewModel()
{
//Can not convert method group to action.
image_MouseEnter = ReactiveCommand.Create(Image_MouseEnterExecute);
//Can not convert method group to action.
imageBrush = ReactiveCommand.Create(Image_MouseEnterExecute);
}
为什么我不设置对属性OpacityMask
的绑定,问题是我有很多图像是在运行时创建的。我不希望所有图像同时更改,也不希望为每个图像创建一个OpacityMask
属性。
我希望有经验的人可以帮助我。