Hey guys (: I'm currently working on this project which consists of zoom function. Now, I am facing this problem where the zoom function that used by me required four mouse events, which are Mouse wheel, Mouse left button up, down etc. However, I am trying to make it like when a button is clicked, the zoom function can be carried out eventually. However, I faced problem in calling mouse event functions using button. Here is the code, please help me out (: thanks alot DDDDD
private void image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
imagePicture.CaptureMouse();
var tt = (TranslateTransform)((TransformGroup)imagePicture.RenderTransform).Children.First(tr => tr is TranslateTransform);
start = e.GetPosition(border);
origin = new Point(tt.X, tt.Y);
}
private void image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
imagePicture.ReleaseMouseCapture();
}
private void image_MouseMove(object sender, MouseEventArgs e)
{
if (!imagePicture.IsMouseCaptured) return;
var tt = (TranslateTransform)((TransformGroup)imagePicture.RenderTransform).Children.First(tr => tr is TranslateTransform);
Vector v = start - e.GetPosition(border);
tt.X = origin.X - v.X;
tt.Y = origin.Y - v.Y;
}
private void image_mousewheel(object sender, MouseWheelEventArgs e)
{
TransformGroup transformGroup = (TransformGroup)imagePicture.RenderTransform;
ScaleTransform transform = (ScaleTransform)transformGroup.Children[0];
RenderOptions.SetBitmapScalingMode(imagePicture, BitmapScalingMode.NearestNeighbor);
double zoom = e.Delta > 0 ? .01 : -.01;
transform.ScaleX += zoom; transform.ScaleY += zoom;
}
Again, my question is How am i going to execute those four mouse event function ONLY WHEN THE BUTTON IS CLICKED, instead of being able to zoom straight when the mouse is brought to the image. For you info, the name of the image is called(image). I've tried binding method, unfortunately it doesn't work;(
Regards.