I’ve verified it steps thru the code as I would expect; however, it only ever zooms in further. The intent of this modifier is to only zoom out when the mouse is dragged up and left. I.e.
Mouse down
Drag up/left
Mouse up
class ZoomOutModifier : ZoomExtentsModifier
{
double _x;
double _y;
MouseButtons _button = MouseButtons.None;
public override void OnModifierDoubleClick(ModifierMouseArgs e)
{
// do not zoom to extents on a double click
e.Handled = true;
}
public override void OnModifierMouseDown(ModifierMouseArgs e)
{
base.OnModifierMouseDown(e);
// where was the mouse button on the chart surface?
_x = e.MousePoint.X;
_y = e.MousePoint.Y;
// which button was clicked? we're only going to zoom
// out on a left button click.
_button = e.MouseButtons;
}
public override void OnModifierMouseUp(ModifierMouseArgs e)
{
// are we left and up from where the mouse was clicked?
if (MouseButtons.Left == _button &&
e.MousePoint.X < _x &&
e.MousePoint.Y < _y)
{
using (var updater = ParentSurface.SuspendUpdates())
{
ParentSurface.ZoomExtents();
ParentSurface.ResumeUpdates(updater);
}
e.Handled = true;
}
else
base.OnModifierMouseUp(e);
}
}
- Chris Kirkman asked 4 years ago
- You must login to post comments
Andrew. I was able to resolve this using
ParentSurface.AnimateZoomExtents(new System.TimeSpan(0, 0, 0, 0, 250));
in my derived ZoomExtentsModifier class. When I used
ParentSurface.ZoomExtents();
it didn’t zoom out, in fact it continued to zoom in. You think this is because I had setup my chart surface to animate in the XAML?
<s:RubberBandXyZoomModifier IsAnimated="True" IsXAxisOnly="False" />
This may have nothing to do with it but would be curious if it did.
- Chris Kirkman answered 4 years ago
- You must login to post comments
Please find attached class that I’m using. Unfortunately it’s not working. Maybe you can get it to work.
class ZoomOutModifier : ZoomExtentsModifier
{
double _x;
double _y;
MouseButtons _button = MouseButtons.None;
public override void OnModifierDoubleClick(ModifierMouseArgs e)
{
// do not zoom to extents on a double click
e.Handled = true;
}
public override void OnModifierMouseDown(ModifierMouseArgs e)
{
base.OnModifierMouseDown(e);
// where was the mouse button on the chart surface?
_x = e.MousePoint.X;
_y = e.MousePoint.Y;
// which button was clicked? we're only going to zoom
// out on a left button click.
_button = e.MouseButtons;
}
public override void OnModifierMouseUp(ModifierMouseArgs e)
{
// are we left and up from where the mouse was clicked?
if (MouseButtons.Left == _button &&
e.MousePoint.X < _x &&
e.MousePoint.Y < _y)
{
ParentSurface.ZoomExtents();
//e.Handled = true;
}
else
base.OnModifierMouseUp(e);
}
}
- Chris Kirkman answered 4 years ago
- You must login to post comments
Thanks Andrew. That’s actually what I did originally and it would just zoom in even more. I get the same behavior with e.Handled true or false.
// are we left and up from where the mouse was clicked?
if (MouseButtons.Left == _button &&
e.MousePoint.X < _x &&
e.MousePoint.Y < _y)
{
ParentSurface.ZoomExtents();
//e.Handled = true;
}
else
base.OnModifierMouseUp(e);
- Chris Kirkman answered 4 years ago
- last edited 4 years ago
- You must login to post comments
Hi Chris
The only thing I can see is wrong is this part
using (var updater = ParentSurface.SuspendUpdates())
{
ParentSurface.ZoomExtents();
ParentSurface.ResumeUpdates(updater);
}
Firstly, when calling a single call to ZoomExtents, you don’t need to suspend updates. secondly, calling ParentSurface.REsumeUpdates(updater) resumes twice, as the dispose block of updater does exactly this.
The pattern should be
using (var updater = ParentSurface.SuspendUpdates())
{
// TODO
// lots of updates here where you want to suspend
// ParentSurface.ResumeUpdates(updater); // DONT CALL THIS
}
Try just calling ParentSurface.ZoomExtents() or AnimateZoomExtents and see what happens
Best regards,
Andrew
- Andrew Burnett-Thompson answered 4 years ago
-
Thanks Andrew. That’s actually where I started. Please see comments below.
- You must login to post comments
Please login first to submit.