Reputation: 549
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?
Upvotes: 0
Views: 259
Reputation: 549
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});
}
Upvotes: 1