FCin
FCin

Reputation: 3915

How to zoom in programmatically?

I'm working on ability to zoom in by clicking on a button, just like I can with my mouse scroll. I tried setting MinValue and MaxValue for X axis, but when I do this, then zooming with mouse scroll gets broken and stops updating MinValue and MaxValue. How can I zoom in without breaking mouse scroll zoom?

private double? _minX;
public double? MinX {
    get => _minX;
    set => SetValue(ref _minX, value);
}

public void ZoomIn()
{
    if (MinX == null || MaxX == null)
        return;

    MaxX -= 1000;
    MinY = null;
    MaxY = null;
}

And my view:

<Button Content="+" Width="25" Height="25" Margin="2" cal:Message.Attach="[Event Click] = [ZoomIn()]"></Button>
<lvc:CartesianChart Series="{Binding SeriesCollection}" Zoom="X" Pan="X">
    <lvc:CartesianChart.AxisX>
        <lvc:Axis MinValue="{Binding MinX, FallbackValue=0}" MaxValue="{Binding MaxX, FallbackValue=100}" 
                  LabelFormatter="{Binding FormatterX}"></lvc:Axis>
    </lvc:CartesianChart.AxisX>
</lvc:CartesianChart>

Upvotes: 0

Views: 1068

Answers (1)

FCin
FCin

Reputation: 3915

I figured it out. I had to set Mode=TwoWay for axis:

<lvc:CartesianChart.AxisX>
    <lvc:Axis MinValue="{Binding MinX, Mode=TwoWay}" MaxValue="{Binding MaxX, Mode=TwoWay}" 
              LabelFormatter="{Binding FormatterX}"></lvc:Axis>
</lvc:CartesianChart.AxisX>

Upvotes: 1

Related Questions