Inherited DatePicker.OnSelectedDateChanged event fired multiple times

Jan 20, 2010 at 2:48 AM

I inherited the DatePicker, and noticed if i chg the date through code myDP.SelectedDate = newDate,

the myDP.OnSelectedDateChanged is fired multiple times, instead of 1!

i tried with 2 myDP, the result is 1st myDP will fired twice, while the 2nd will fired 4 times.

I chk the SelectionChangedEventArgs, the Source/OriginalSource is null b4 i pass into base.OnSelectedDateChanged(), so i don't have much clue how to handle this.

        protected override void OnSelectedDateChanged(SelectionChangedEventArgs e)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("pre base");
            if (e.Source != null)
            {
                sb.AppendLine("Source Nm: " + e.Source.GetType().Name);
            }
            sb.AppendLine("Source: " + e.Source);
            if (e.OriginalSource != null)
            {
                sb.AppendLine("OriginalSource Nm: " + e.OriginalSource.GetType().Name);
            }
            sb.AppendLine("OriginalSource: " + e.OriginalSource);
            sb.AppendLine("Handled: " + e.Handled);
            sb.AppendLine("RoutedEvent: " + e.RoutedEvent);

            base.OnSelectedDateChanged(e);

            sb.AppendLine("post base");
            if (e.Source != null)
            {
                sb.AppendLine("Source Nm: " + e.Source.GetType().Name);
            }
            sb.AppendLine("Source: " + e.Source);
            if (e.OriginalSource != null)
            {
                sb.AppendLine("OriginalSource Nm: " + e.OriginalSource.GetType().Name);
            }
            sb.AppendLine("OriginalSource: " + e.OriginalSource);
            sb.AppendLine("Handled: " + e.Handled);
            sb.AppendLine("RoutedEvent: " + e.RoutedEvent);

            System.Diagnostics.Debug.WriteLine(sb.ToString());
        }

I expecting the handler suppose to fired 1 time only.

Apr 30, 2010 at 7:16 AM
exactly the same issue for me :(