コード例 #1
0
        void OnItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
            ItemPoints.Clear();
            Points.Clear();

            foreach (object item in ItemsSource)
            {
                ItemPoints.Add(new ItemPoint(item));
                Points.Add(new Point());
            }

            // Also check for INotifyPropertyChanged
            if (args.OldItems != null)
            {
                foreach (object item in args.OldItems)
                {
                    if (item is INotifyPropertyChanged)
                    {
                        (item as INotifyPropertyChanged).PropertyChanged -= OnItemPropertyChanged;
                    }
                }
            }
            if (args.NewItems != null)
            {
                foreach (object item in args.NewItems)
                {
                    if (item is INotifyPropertyChanged)
                    {
                        (item as INotifyPropertyChanged).PropertyChanged += OnItemPropertyChanged;
                    }
                }
            }

            CalculateAxisScalers();
        }
コード例 #2
0
        void OnItemsSourceChanged(DependencyPropertyChangedEventArgs args)
        {
            // Transfer new collection of items in ItemsSource to ItemPoints
            ItemPoints.Clear();
            Points.Clear();

            if (args.NewValue != null)
            {
                foreach (object item in ItemsSource)
                {
                    ItemPoints.Add(new ItemPoint(item));
                    Points.Add(new Point());
                }
            }

            // Install (or remove) handlers for CollectionChanged event
            if (args.OldValue is INotifyCollectionChanged)
            {
                (args.OldValue as INotifyCollectionChanged).CollectionChanged -= OnItemsSourceCollectionChanged;
            }

            if (args.NewValue is INotifyCollectionChanged)
            {
                (args.NewValue as INotifyCollectionChanged).CollectionChanged += OnItemsSourceCollectionChanged;
            }

            CalculateAxisScalers();
        }