Page 1 of 1

Dependency property of the array

Posted: Mon May 12, 2014 6:29 am
by minoru

Code: Select all

using System;
using System.Windows;
using System.Windows.Threading;

using Arction.WPF.LightningChartUltimate;
using Arction.WPF.LightningChartUltimate.SeriesXY;

namespace ArrayPoints
{
    public partial class MainWindow : Window
    {
        private LightningChartUltimate m_chart;
        private PointLineSeries m_pls;

        private DispatcherTimer dt;
        private Random rand = new Random();

        SeriesPoint[] sp;

        public MainWindow()
        {
            InitializeComponent();

            m_chart = new LightningChartUltimate();

            m_chart.BeginUpdate();
            m_chart.ViewXY.Margins = new Thickness(60, 30, 20, 40);
            m_chart.ViewXY.XAxes[0].ValueType = AxisValueType.Number;
            m_pls = new PointLineSeries(m_chart.ViewXY, m_chart.ViewXY.XAxes[0], m_chart.ViewXY.YAxes[0]);
            m_chart.ViewXY.PointLineSeries.Add(m_pls);
            sp = new SeriesPoint[10];
            for (int ii = 0; ii < 10; ++ii)
            {
                sp[ii].X = (double)ii;
                sp[ii].Y = (double)rand.Next(0, 100) / 10.0;
            }
            m_pls.Points = sp;      // Update points !
            m_chart.EndUpdate();

            this.chart1.Children.Add(m_chart);

            dt = new DispatcherTimer() { Interval = new TimeSpan(0, 0, 0, 0, 100) };
            dt.Tick += (s, e) =>
            {
                for (int ii = 0; ii < 10; ++ii)
                {
                    sp[ii].Y = (double)rand.Next(0, 100) / 10.0;
                }
                m_chart.BeginUpdate();
                //m_pls.Points = null;
                m_pls.Points = sp;      // Update points !
                m_chart.EndUpdate();
            };
            dt.Start();
        }
    }
}
v.5:

The waveform changes in real time.

v.6:

The waveform does not change in real time. :o

If m_pls.Points = null beforehand, the waveform changes. ( line 50 )
But, it is not beautiful. ;)

Dependency property of the array has become so.

Regards,
Minoru

Re: Dependency property of the array

Posted: Mon May 12, 2014 10:52 am
by ArctionTero
Hi Minoru,

Yes, the Points array is now a dependency property (dp). So if you use same array and update only the values, then the data behind the dp array does not change, because the dp value does not change.

You could also clear the Points by

Code: Select all

m_pls.ClearValue(PointLineSeries.PointsProperty);
but ugly it remains.

The data behind the array is not dp due performance reasons.

We are working on solution to this.