Hi, I'm binding my ChartView to RadObservableCollection in a ViewModel, but I'm getting exceptions about trying to add to collection during CollectionChanged event handler working.
I'm suspending collection's notifications and resume them after adding element, but still getting this error (btw, only when chart becoming visible). Doing that from separate thread through Dispatcher.Invoke, also tried without that - not helping.
There are about 5-10 add operations per second. Can be more, can be less sometimes.
I was even trying to lock collection with locker object and then with (Collection as ICollection).SyncRoot. It doesn't help, only changing exception to InvalidArgumentException (index is out of range).
So, I'm frustrated
I'm suspending collection's notifications and resume them after adding element, but still getting this error (btw, only when chart becoming visible). Doing that from separate thread through Dispatcher.Invoke, also tried without that - not helping.
There are about 5-10 add operations per second. Can be more, can be less sometimes.
I was even trying to lock collection with locker object and then with (Collection as ICollection).SyncRoot. It doesn't help, only changing exception to InvalidArgumentException (index is out of range).
So, I'm frustrated
<
telerik:RadCartesianChart
x:Name
=
"Chart"
EmptyContent
=
"Нет данных"
Grid.Row
=
"0"
Grid.Column
=
"0"
Grid.ColumnSpan
=
"2"
>
<
telerik:RadCartesianChart.Grid
>
<
telerik:CartesianChartGrid
MajorLinesVisibility
=
"None"
StripLinesVisibility
=
"XY"
>
<
telerik:CartesianChartGrid.YStripeBrushes
>
<
SolidColorBrush
Color
=
"SlateGray"
/>
<
SolidColorBrush
Color
=
"SlateGray"
Opacity
=
"0.8"
/>
</
telerik:CartesianChartGrid.YStripeBrushes
>
</
telerik:CartesianChartGrid
>
</
telerik:RadCartesianChart.Grid
>
<
telerik:RadCartesianChart.VerticalAxis
>
<
telerik:LinearAxis
Minimum
=
"0"
MajorStep
=
"5"
Maximum
=
"100"
FontFamily
=
"Segoe UI"
FontSize
=
"16"
FontWeight
=
"Bold"
HorizontalLocation
=
"Left"
ElementBrush
=
"Black"
/>
</
telerik:RadCartesianChart.VerticalAxis
>
<
telerik:RadCartesianChart.HorizontalAxis
>
<
telerik:DateTimeContinuousAxis
MajorStepUnit
=
"Minute"
LabelInterval
=
"10"
FontFamily
=
"Segoe UI"
PlotMode
=
"OnTicks"
LabelFormat
=
"HH:mm:ss.f"
Minimum
=
"{Binding HeatStartTime}"
Maximum
=
"{Binding HeatEndTime}"
/>
</
telerik:RadCartesianChart.HorizontalAxis
>
<
telerik:LineSeries
CategoryBinding
=
"Time"
ValueBinding
=
"CO"
ItemsSource
=
"{Binding GasAnalysisChartData}"
Stroke
=
"Red"
StrokeThickness
=
"2"
>
</
telerik:LineSeries
>
<
telerik:LineSeries
CategoryBinding
=
"Time"
ValueBinding
=
"H2"
ItemsSource
=
"{Binding GasAnalysisChartData}"
Stroke
=
"Lime"
StrokeThickness
=
"2"
>
</
telerik:LineSeries
>
<
telerik:LineSeries
CategoryBinding
=
"Time"
ValueBinding
=
"N2"
ItemsSource
=
"{Binding GasAnalysisChartData}"
Stroke
=
"Black"
StrokeThickness
=
"2"
>
</
telerik:LineSeries
>
<
telerik:LineSeries
CategoryBinding
=
"Time"
ValueBinding
=
"O2"
ItemsSource
=
"{Binding GasAnalysisChartData}"
Stroke
=
"Blue"
StrokeThickness
=
"2"
>
</
telerik:LineSeries
>
<
telerik:LineSeries
CategoryBinding
=
"Time"
ValueBinding
=
"Ar"
ItemsSource
=
"{Binding GasAnalysisChartData}"
Stroke
=
"Fuchsia"
StrokeThickness
=
"2"
>
</
telerik:LineSeries
>
<
telerik:LineSeries
CategoryBinding
=
"Time"
ValueBinding
=
"CO2"
ItemsSource
=
"{Binding GasAnalysisChartData}"
Stroke
=
"Yellow"
StrokeThickness
=
"2"
>
</
telerik:LineSeries
>
</
telerik:RadCartesianChart
>
private
void
ProcessGasAnalysisDataPiece(FlexEvent fex)
{
lock
((GasAnalysisChartData
as
ICollection).SyncRoot)
{
var gdata =
new
GasAnalysisChartDataModel
{
Ar = (
double
)fex.Arguments[
"Ar"
],
CO = (
double
)fex.Arguments[
"CO"
],
CO2 = (
double
)fex.Arguments[
"CO2"
],
H2 = (
double
)fex.Arguments[
"H2"
],
N2 = (
double
)fex.Arguments[
"N2"
],
O2 = (
double
)fex.Arguments[
"O2"
],
Time = fex.Time
};
GasAnalysisChartData.SuspendNotifications();
GasAnalysisChartData.Add( gdata );
GasAnalysisChartData.ResumeNotifications();
}