【问题标题】:SciChart throws an exception on new axis insertionSciChart 在插入新轴时抛出异常
【发布时间】:2020-03-17 11:28:36
【问题描述】:

我有两个AxisCollections:

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

两者都分别绑定到SciChartSurfaceXAxesYAxes

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

我尝试使用以下方法添加轴:

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

添加第二个 X 轴会导致异常:

“SciChartSurface 没有渲染,因为抛出了异常: 消息:Ein Element mit dem gleichen Schlüssel wurde bereits hinzugefügt。”

什么意思是“已经添加了具有相同密钥的项目”。我假设(虽然不确定)它的发生是因为所有创建的轴都具有相同的 x:Key

我该如何解决这个问题?

【问题讨论】:

    标签: c# wpf scichart


    【解决方案1】:

    为每个轴添加一个唯一的 ID 可以解决问题:

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

    【讨论】:

      猜你喜欢
      • 2010-12-22
      • 1970-01-01
      • 1970-01-01
      • 2011-04-24
      • 2013-05-24
      • 2017-09-30
      • 2017-09-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多