We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Slight bug with ListenPropertyChange

I know this might be a not so common situation, but there is a slight bug with the sfChart and how it listens for property changes

So if I have an ObservableCollection<myClass> which is bound to the chart ItemSource
Some of the items in the collection are say myClass2, which derives from myClass and implents IPropertyNotify, though the base class doesn't.
Hope you are with me so far ..
Now at this point the chart won't listen for property updates of any of the myClass2 objects in the collection.
Worth noting at this point, that sfDataGrid is fine and handles this correctly.
HOWEVER .. if i now add after binding a new item to the collection, of myClass2 -  the chart will update with property changes for that object - so it partially works.

Thanks

3 Replies

MK Muneesh Kumar G Syncfusion Team March 11, 2019 12:53 AM

Hi Tom, 
 
Greetings from Syncfusion, we have analyzed your query and we are unable to get your exact problem in that.  
 
If you have enabling ListenPropertyChange property, registers PropertyChanged event of every object in the data source. And it works fine with complex object also.  
 
We have prepared a simple sample with your scenario, please check the sample form the following location.  
 
 
If you still face any problem, can you revert us by modifying the attached sample based on your application scenario, this will help us to provide you a better solution at the earliest.  
   
Thanks, 
Muneesh Kumar G.  
 



TO Tom March 12, 2019 04:19 PM

Thank you for looking into it
I have modified your code to illustrate the problem.
If you replace the code in your sample with that below it doesn't update, and illustrates the problem
If you change the  references from Model  to Model2
ie these ones
       private ObservableCollection<Model> data;
        public ObservableCollection<Model> Data
 Data.Add(new Model()

then it will work.



----



using Syncfusion.UI.Xaml.Charts;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections;

namespace Sample1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        Random rd = new Random();
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            viewModel.Data[6].YValue = rd.Next(0, 50);
            viewModel.Data[6].ZValue = rd.Next(0, 10);
            ((Model2)viewModel.Data[6]).OnPropertyChanged("YValue");
            ((Model2)viewModel.Data[6]).OnPropertyChanged("ZValue");
        }
    }

    public class Model
    {
        private double xValue;

        public double XValue
        {
            get { return xValue; }
            set { xValue = value; //OnPropertyChanged("XValue"); 
            }
        }

        private double yValue;

        public double YValue
        {
            get { return yValue; }
            set { yValue = value; //OnPropertyChanged("YValue"); 
            }
        }

        private double zValue;

        public double ZValue
        {
            get { return zValue; }
            set { zValue = value;
                //OnPropertyChanged("ZValue"); 

            }
        }

    }

    public class Model2 :Model, INotifyPropertyChanged
    {
   

        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(string name)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
        }
    }

    public class ViewModel
    {
        public ViewModel()
        {
            GenerateData();           
        }

        public void GenerateData()
        {
            Data = new ObservableCollection<Model>();
            Random rd = new Random();
            for (int i = 0; i < 6; i++)
            {
                Data.Add(new Model()
                {
                    XValue = i,
                    YValue = rd.Next(0, 50),
                    ZValue=rd.Next(0,10)
                });
            }

            Data.Add(new Model2()
            {
                XValue = 6,
                YValue = rd.Next(0, 50),
                ZValue = rd.Next(0, 10)
            });
        }

        private ObservableCollection<Model> data;

        public ObservableCollection<Model> Data
        {
            get { return data; }
            set { data = value;  }
        }

        
       
    }
    
}



MK Muneesh Kumar G Syncfusion Team March 13, 2019 01:59 AM

Hi Tom,  
 
Thanks for your information.  
 
We have analyzed the reported issue with provided code snippet and we were able to reproduce the reported problem at our end. You can resolve this problem by extending BubbleSeries as per the below code snippet.  
 
Code snippet  
    public class BubbleSeriesExt : BubbleSeries 
    { 
        protected override void OnDataSourceChanged(IEnumerable oldValue, IEnumerable newValue) 
        { 
            base.OnDataSourceChanged(oldValue, newValue); 
        
            if(ItemsSource != null && ListenPropertyChange) 
            foreach (var item in ItemsSource as IEnumerable) 
            { 
                INotifyPropertyChanged data = item as INotifyPropertyChanged; 
                if (data != null) 
                { 
                    data.PropertyChanged -= OnItemPropertyChanged; 
                    data.PropertyChanged += OnItemPropertyChanged; 
 
                } 
            } 
        } 
 
        void OnItemPropertyChanged(object sender, PropertyChangedEventArgs e) 
        { 
            int position = -1; 
            IEnumerable itemsSource = (ItemsSource as IEnumerable); 
            foreach (object obj in itemsSource) 
            { 
                position++; 
 
                if (obj == sender) 
                    break; 
            } 
 
            SetIndividualPoint(position, sender, true); 
 
            UpdateArea(); 
        } 
    } 
 
 
 
<chart:SfChart  Grid.Row="1" 
                       x:Name="chart" > 
.. 
            <local:BubbleSeriesExt XBindingPath="XValue" YBindingPath="YValue"  
                                Size="ZValue" ListenPropertyChange="True" 
                                ItemsSource="{Binding Data}"/> 
 
        </chart:SfChart> 
 
 
We have modified our sample based on this, please find the sample from the following location.  
 
 
Please let us know if you have any queries.  
 
Thanks, 
Muneesh Kumar G. 


Loader.
Live Chat Icon For mobile
Up arrow icon