I have created a usercontrol for livechart and trying to create dependency properties around it. But the dependency property is not getting updated. I googled and found a answer in StackOverflow. so I have been searching around. i followed the steps as mentioned in the answer still i am not able to get the chart updated. CODE:-
<LiveChart:CartesianChart Grid.Row="1" Background="White">
<LiveChart:CartesianChart.AxisX>
<LiveChart:Axis Title="{Binding Path=XAxisTitle, ElementName=chartControl, UpdateSourceTrigger=PropertyChanged}" Labels="{Binding Path=XAxisValues, ElementName=chartControl, UpdateSourceTrigger=PropertyChanged}"/>
</LiveChart:CartesianChart.AxisX>
<LiveChart:CartesianChart.AxisY>
<LiveChart:Axis Title="{Binding Path=YAxisTitle, ElementName=chartControl, UpdateSourceTrigger=PropertyChanged}" LabelFormatter="{Binding Path=Formatter, ElementName=chartControl, UpdateSourceTrigger=PropertyChanged}" MinValue="0"></LiveChart:Axis>
</LiveChart:CartesianChart.AxisY>
<LiveChart:CartesianChart.Series>
<LiveChart:LineSeries Values="{Binding Path=SpectrumChartSeries, ElementName=chartControl, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"></LiveChart:LineSeries>
</LiveChart:CartesianChart.Series>
</LiveChart:CartesianChart>
I have named the user control as chartControl and used the ElementName. My backend:-
public List<Point> ChartPoints
{
get { return (List<Point>)GetValue(ChartPointsProperty); }
set { SetValue(ChartPointsProperty, value); }
}
public static readonly DependencyProperty ChartPointsProperty = DependencyProperty.Register("ChartPoints", typeof(List<Point>), typeof(chartcontrol), new FrameworkPropertyMetadata(new List<Point>(), onChartrPointChange));
private static void onChartrPointChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var control = d as chartcontrol;
var points = e.NewValue as List<Point>;
control.UpdateChart(points);
}
private void UpdateChart(List<Point> chartPoints)
{
SpectrumChartSeries = new ChartValues<double>();// { 4, 6, 5, 2, 4, 8, 9, 10, 20, 11, 15 };
SpectrumChartSeries.AddRange(chartPoints.Select(x => x.Y));
XAxisValues = chartPoints.Select(x => x.X.ToString()).ToList();//new List<string>() { "1", "2", "3", "4", "5" };
Formatter = value => (value).ToString("N", System.Globalization.CultureInfo.CurrentCulture);
XAxisTitle = " test title";
YAxisTitle = "y title";
}
The changed event is getting hit and the values are updated. but still not reflecting in the chart. so bit confused.
The thing is when i try to Use the WPF tool Snoop and click on the line series, i can see that the chart get updated immediately,