public partial class MainWindow : Window
{
private double zoomScale = 1.0;
public MainWindow()
{
InitializeComponent();
}
private void ZoomedImage_MouseWheel(object sender, MouseWheelEventArgs e)
{
// Get the mouse position relative to the image
Point mousePos = e.GetPosition(imagemap);
// Adjust the zoom scale based on the mouse wheel delta
double delta = e.Delta > 0 ? 0.1 : -0.1;
zoomScale += delta;
// Constrain the zoom scale within reasonable limits
zoomScale = Math.Max(1.0, Math.Min(zoomScale, 10.0));
// Apply the zoom scale using a ScaleTransform
ScaleTransform scaleTransform = new ScaleTransform(zoomScale, zoomScale);
// Set the center of the ScaleTransform to the mouse position
scaleTransform.CenterX = mousePos.X;
scaleTransform.CenterY = mousePos.Y;
imagemap.RenderTransform = scaleTransform;
e.Handled = true; // Prevent scrolling
}
}
public partial class MainWindow : Window
{
private double zoomScale = 1.0;
public MainWindow()
{
InitializeComponent();
}
private void ZoomedImage_MouseWheel(object sender, MouseWheelEventArgs e)
{
// Get the mouse position relative to the image
Point mousePos = e.GetPosition(imagemap);
// Adjust the zoom scale based on the mouse wheel delta
double delta = e.Delta > 0 ? 0.1 : -0.1;
zoomScale += delta;
// Constrain the zoom scale within reasonable limits
zoomScale = Math.Max(1.0, Math.Min(zoomScale, 10.0));
// Apply the zoom scale using a ScaleTransform
ScaleTransform scaleTransform = new ScaleTransform(zoomScale, zoomScale);
// Set the center of the ScaleTransform to the mouse position
scaleTransform.CenterX = mousePos.X;
scaleTransform.CenterY = mousePos.Y;
imagemap.RenderTransform = scaleTransform;
e.Handled = true; // Prevent scrolling
}
}