使用MVVM放大和缩小鼠标点击的图像



在这个应用程序中,我使用按钮在WPF中使用MVVM放大和缩小图像。单击"放大"按钮时,高度和宽度会增加一个特定的量,反之亦然。但是我想用鼠标双击来达到同样的效果。是否有任何方法来实现相同的使用MVVM?

private ICommand zoomOutCommand;
public ICommand ZoomOutCommand {
get {
if (zoomOutCommand == null) {
zoomOutCommand = new RelayCommand < object > (ZoomOutExecute, OutReturnBool, false);
}
return zoomOutCommand;
}
}
private ICommand zoomInCommand;
public ICommand ZoomInCommand {
get {
if (zoomInCommand == null) {
zoomInCommand = new RelayCommand < object > (ZoomInExecute, InReturnBool, false);
}
return zoomInCommand;
}
}
private void ZoomInExecute(object obj) {
//  Scale += stepScale;
Height *= 1.2;
Width *= 1.2;
}
private bool InReturnBool(object obj) {
if (Height > 6 * iniWidth) return false;
else return true;
}
private bool OutReturnBool(object obj) {
if (Height < 0.1 * iniHeight) return false;
else return true;
}
private void ZoomOutExecute(object obj) {
Height *= 0.8;
Width *= 0.8;
}
private const double iniWidth = 500;
private double width = iniWidth;
public double Width {
get {
return width;
}
set {
width = value;
NotifyPropertyChanged("Width");
}
}
private const double iniHeight = 500;
private double height = iniHeight;
public double Height {
get {
return height;
}
set {
height = value;
NotifyPropertyChanged("Height");
}
}

对于双击,可以这样绑定命令

<Button>
<Button.InputBindings>
<MouseBinding Gesture="LeftDoubleClick" Command="{Binding YourCommand}" />
</Button.InputBindings>
</Button>

最新更新