DependencyProperty in Silverlight

C#

Public Domain

Download (right click, save as, rename as appropriate)

Embed

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
        public KpiInfo SelectedKpiInfo
        {
            get { return (KpiInfo)GetValue(SelectedKpiInfoProperty); }
            set { SetValue(SelectedKpiInfoProperty, value); } //Never put code here! Put it in onMyPropertyChanged
        }

        public event SelectionChangedEventHandler OnSelectedKpiInfoChanged;

        public static readonly DependencyProperty SelectedKpiInfoProperty =
        	DependencyProperty.Register("SelectedKpiInfo", typeof(KpiInfo), typeof(KpiInfoList), new PropertyMetadata(null, SelectedKpiInfoChanged));

        private static void SelectedKpiInfoChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            KpiInfoList control = d as KpiInfoList;
            control.kpiInfoDataGrid.SelectedItem = e.NewValue;
        }