datepicker is in infinite loop

Aug 10, 2010 at 3:35 PM
Edited Aug 10, 2010 at 3:46 PM
<font size="2" color="#0000ff">

<

</font>

my:DatePicker Height="25" Margin="218.543,350,0,0" Name="datePickerstartdate" VerticalAlignment="Top" xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit" Text="Show this" SelectedDateChanged="datePickerstartdate_SelectedDateChanged" LostFocus="datePickerstartdate_LostFocus" HorizontalAlignment="Left" Width

="115" />


----

private void datePickerstartdate_SelectedDateChanged(object sender, SelectionChangedEventArgs e)

        {
            isthereanychange = true;   //private variable        
        }


private void datePickerstartdate_LostFocus(object sender, RoutedEventArgs e)
        {
            checkdatePickerstartdate();
        }

private void checkdatePickerstartdate()
        {
            TextBlock popupText = new TextBlock();
            popupText.Background = Brushes.LightBlue;
            popupText.Foreground = Brushes.Red;
            if (datePickerstartdate.SelectedDate == null)
            {
                popupText.Text = "Start Date is required!";
                popupshowerror.PlacementTarget = datePickerstartdate;
                popupshowerror.Child = popupText;
                popupshowerror.IsOpen = true;
                popupshowerror.StaysOpen = true;               
                btncreate.IsEnabled = false;
                Isthereproblem = true;
                datePickerstartdate.Focus();
            }
            else
            {
                                hidedisplaywindow();
            }
        }

when I click the calender, it gives the "System.StackOverflowException was unhandled".

I traced the error because it caused the infinite loop due to datePickerstartdate.Focus() step.  It seems whenever this step causes to call datePickerstartdate_LostFocus function again.

If I comment this step datePickerstartdate.Focus(), no error again. I think this is bug. Can anyone explain this?

Thanks in advance!