Example #1
0
        private void OnChartPanelChanged(DependencyObject source)
        {
            if (_chartElements != null)
            {
                ((INotifyCollectionChanged)_chartElements).CollectionChanged -= OnChartElementsChanged;
                _chartElements = null;
            }

            if (source != null)
            {
                var chartPanel = source.GetVisualSubtree().OfType<ChartPanel>().FirstOrDefault();
                if (chartPanel != null)
                {
                    _chartElements = chartPanel.ChartElements;
                    ((INotifyCollectionChanged)_chartElements).CollectionChanged += OnChartElementsChanged;
                }
            }

            Update();
        }
Example #2
0
        private void OnPieChartChanged(DependencyObject source)
        {
            // Unsubscribe from previous collection.
            if (_pieChartSubscription != null)
            {
                _pieChartSubscription.Dispose();
                _pieChartSubscription = null;
            }

            // Get pie chart from source.
            if (source != null)
                _pieChart = source.GetVisualSubtree().OfType<PieChart>().FirstOrDefault();

            if (_pieChart != null)
            {
                // Bind legend title to pie chart title.
                SetBinding(TitleProperty, new Binding("Title") { Source = _pieChart });

                // Subscribe to changes in pie chart using weak event pattern.
                _pieChartSubscription =
                    WeakEventHandler<EventArgs>.Register(
                        _pieChart,
                        this,
                        (sender, handler) => sender.Updated += handler,
                        (sender, handler) => sender.Updated -= handler,
                        (listener, sender, eventArgs) => listener.Update());
            }
            else
            {
                // Reset legend title.
                ClearValue(TitleProperty);
            }

            Update();
        }