如何以编程方式放大?

时间:2018-08-28 17:33:30

标签: c# wpf livecharts

我正在通过单击按钮来进行放大,就像使用鼠标滚动一样。我尝试为MinValue轴设置MaxValueX,但是当我这样做时,使用鼠标滚动进行缩放时会中断,并停止更新MinValueMaxValue。如何在不中断鼠标滚动缩放的情况下进行放大?

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;
}

我的观点:

<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>

1 个答案:

答案 0 :(得分:1)

我知道了。我必须将Mode=TwoWay设置为轴:

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