Ch.Epyx.WindMobile.WP7.View.ChartControl.ChartViewModelChanged C# (CSharp) Method

ChartViewModelChanged() public static method

public static ChartViewModelChanged ( System d, System e ) : void
d System
e System
return void
        public static void ChartViewModelChanged(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e)
        {
            var control = d as ChartControl;
            if (d == null) throw new Exception("Unknown control type");

            var old = e.OldValue as ChartViewModel;
            if (old != null)
            {
                old.ValidChartDataFound -= control.ChartViewModel_ValidChartDataFound;
                old.StartRefreshing -= control.ChartViewModel_StartRefreshing;
            }

            var newV = e.NewValue as ChartViewModel;
            if (newV != null)
            {
                newV.ValidChartDataFound += control.ChartViewModel_ValidChartDataFound;
                newV.StartRefreshing += control.ChartViewModel_StartRefreshing;
                control.MainChart.DataContext = newV;
                control.ButtonPallette.DataContext = newV;
                if (control.Visibility == Visibility.Visible)
                {
                    control.Activate();
                }
            }
        }