简体   繁体   中英

SciChart throws an exception on new axis insertion

I have two AxisCollection s:

    private AxisCollection _xAxes = new AxisCollection();
    public AxisCollection XAxes
    {
        get => _xAxes;
        set 
        {
            _xAxes = value;
            OnPropertyChanged("XAxes");
        }
    }

    private AxisCollection _yAxes = new AxisCollection();
    public AxisCollection YAxes
    {
        get => _yAxes;
        set
        {
            _yAxes = value;
            OnPropertyChanged("YAxes");
        }
    }

Both are binded to XAxes and YAxes of SciChartSurface respectively:

        <s:SciChartSurface Grid.Row="0"
                       Grid.RowSpan="3"
                       Grid.Column="0"
                       Grid.ColumnSpan="2"
                       Panel.ZIndex="0"
                       RenderableSeries="{Binding RenderableSeries}"  
                       ChartTitle="{Binding ChartTitle}"
                       XAxes="{Binding XAxes}"
                       YAxes="{Binding YAxes}">

I try to add axes using following method:

        public void AddAxes()
    {
        XAxes.Add(new NumericAxis() { AxisTitle = "X Achse"});
        XAxes.Add(new NumericAxis() { AxisTitle = "X Achse 2" });
        YAxes.Add(new NumericAxis() { AxisTitle = "Y Achse", AxisAlignment = AxisAlignment.Left});
    }

Addition of a second X axis causes an exception:

"SciChartSurface didn't render, because an exception was thrown: Message: Ein Element mit dem gleichen Schlüssel wurde bereits hinzugefügt."

what means "An item with the same key has already been added". I assume (though not sure) it happens because all of the created axes have the same x:Key .

How can I fix this issue?

Adding a unique Id to each axis solves issue:

    public void AddAxes()
    {
        XAxes.Add(new NumericAxis() { Id = "1", AxisTitle = "X Achse"});
        XAxes.Add(new NumericAxis() { Id = "2", AxisTitle = "X Achse 2" });
        YAxes.Add(new NumericAxis() { AxisTitle = "Y Achse", AxisAlignment = AxisAlignment.Left});
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM