/// <summary>
 /// Inherited code: Requires comment.
 /// </summary>
 /// <param name="calendarButton">Inherited code: Requires comment 1.</param>
 /// <param name="calendarButtonStyle">Inherited code: Requires comment 2.</param>
 private static void EnsureCalendarButtonStyle(GlobalCalendarButton calendarButton, Style calendarButtonStyle)
 {
     Debug.Assert(calendarButton != null, "The calendarButton should not be null!");
     if (calendarButtonStyle != null && calendarButton != null)
     {
         calendarButton.Style = calendarButtonStyle;
     }
 }
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="T:System.Windows.Automation.Peers.GlobalCalendarButtonAutomationPeer" />
 /// class.
 /// </summary>
 /// <param name="owner">
 /// The
 /// <see cref="T:System.Windows.Controls.Primitives.GlobalCalendarButton" />
 /// to associate with this
 /// <see cref="T:System.Windows.Automation.Peers.AutomationPeer" />.
 /// </param>
 public GlobalCalendarButtonAutomationPeer(GlobalCalendarButton owner)
     : base(owner)
 {
 }
        /// <summary>
        /// Inherited code: Requires comment.
        /// </summary>
        private void PopulateGrids()
        {
            if (MonthView != null)
            {
                for (int i = 0; i < GlobalCalendar.RowsPerMonth; i++)
                {
                    if (_dayTitleTemplate != null)
                    {
                        FrameworkElement cell = (FrameworkElement)_dayTitleTemplate.LoadContent();
                        cell.SetValue(Grid.RowProperty, 0);
                        cell.SetValue(Grid.ColumnProperty, i);
                        MonthView.Children.Add(cell);
                    }
                }

                for (int i = 1; i < GlobalCalendar.RowsPerMonth; i++)
                {
                    for (int j = 0; j < GlobalCalendar.ColumnsPerMonth; j++)
                    {
                        GlobalCalendarDayButton cell = new GlobalCalendarDayButton();

                        if (Owner != null)
                        {
                            cell.Owner = Owner;
                            Owner.ApplyDayButtonStyle(cell);
                        }
                        cell.SetValue(Grid.RowProperty, i);
                        cell.SetValue(Grid.ColumnProperty, j);
                        cell.CalendarDayButtonMouseDown += Cell_MouseLeftButtonDown;
                        cell.CalendarDayButtonMouseUp += Cell_MouseLeftButtonUp;
                        cell.MouseEnter += Cell_MouseEnter;
                        cell.MouseLeave += Cell_MouseLeave;
                        cell.Click += Cell_Click;
                        MonthView.Children.Add(cell);
                    }
                }
            }

            if (YearView != null)
            {
                GlobalCalendarButton month;
                int count = 0;
                for (int i = 0; i < GlobalCalendar.RowsPerYear; i++)
                {
                    for (int j = 0; j < GlobalCalendar.ColumnsPerYear; j++)
                    {
                        month = new GlobalCalendarButton();

                        if (Owner != null)
                        {
                            month.Owner = Owner;
                            if (Owner.CalendarButtonStyle != null)
                            {
                                month.Style = Owner.CalendarButtonStyle;
                            }
                        }
                        month.SetValue(Grid.RowProperty, i);
                        month.SetValue(Grid.ColumnProperty, j);
                        month.CalendarButtonMouseDown += Month_CalendarButtonMouseDown;
                        month.CalendarButtonMouseUp += Month_CalendarButtonMouseUp;
                        month.MouseEnter += Month_MouseEnter;
                        month.MouseLeave += Month_MouseLeave;
                        YearView.Children.Add(month);
                        count++;
                    }
                }
            }
        }
        /// <summary>
        /// Inherited code: Requires comment.
        /// </summary>
        /// <param name="calendarButton">Inherited code: Requires comment 1.</param>
        internal void UpdateYearViewSelection(GlobalCalendarButton calendarButton)
        {
            if (Owner != null && calendarButton != null && calendarButton.DataContext is DateTime)
            {
                Owner.FocusCalendarButton.IsCalendarButtonFocused = false;
                Owner.FocusCalendarButton = calendarButton;
                calendarButton.IsCalendarButtonFocused = Owner.HasFocusInternal;

                DateTime date = (DateTime)calendarButton.DataContext;
                if (Owner.DisplayMode == CalendarMode.Year)
                {
                    Owner.SelectedMonth = date;
                }
                else
                {
                    Owner.SelectedYear = date;
                }
            }
        }
 /// <summary>
 /// Inherited code: Requires comment.
 /// </summary>
 /// <param name="sender">Inherited code: Requires comment 1.</param>
 /// <param name="e">Inherited code: Requires comment 2.</param>
 private void Month_MouseLeave(object sender, MouseEventArgs e)
 {
     if (_isMouseLeftButtonDownYearView)
     {
         GlobalCalendarButton b = sender as GlobalCalendarButton;
         // The button is in Pressed state. Change the state to normal.
         b.ReleaseMouseCapture();
         if (_downEventArgYearView != null)
         {
             b.SendMouseLeftButtonUp(_downEventArgYearView);
         }
         _lastCalendarButton = b;
     }
 }