Beispiel #1
0
 private void Month_MouseEnter(object sender, MouseEventArgs e)
 {
     if (_isMouseLeftButtonDownYearView)
     {
         CalendarButton b = sender as CalendarButton;
         Debug.Assert(b != null);
         UpdateYearViewSelection(b);
     }
 }
Beispiel #2
0
        private void SetYearButtons(int decade, int decadeEnd)
        {
            int year;
            int count = -1;

            foreach (object child in _yearView.Children)
            {
                CalendarButton childButton = child as CalendarButton;
                Debug.Assert(childButton != null);
                year = decade + count;

                if (year <= DateTime.MaxValue.Year && year >= DateTime.MinValue.Year)
                {
                    //There should be no time component. Time is 12:00 AM
                    DateTime day = new DateTime(year, 1, 1);
                    childButton.DataContext = day;
                    childButton.Content     = year.ToString(DateTimeHelper.GetCurrentDateFormat());
                    childButton.Visibility  = Visibility.Visible;

                    if (this.Owner != null)
                    {
                        if (year == this.Owner.SelectedYear.Year)
                        {
                            this.Owner.FocusCalendarButton = childButton;
                            childButton.IsFocusedOverride  = this.Owner._hasFocus;
                        }
                        else
                        {
                            childButton.IsFocusedOverride = false;
                        }
                        childButton.IsSelected = (Owner.DisplayDate.Year == year);

                        if (year < this.Owner.DisplayDateRangeStart.Year || year > this.Owner.DisplayDateRangeEnd.Year)
                        {
                            childButton.IsEnabled = false;
                            childButton.Opacity   = 0;
                        }
                        else
                        {
                            childButton.IsEnabled = true;
                            childButton.Opacity   = 1;
                        }
                    }

                    //SET IF THE YEAR IS INACTIVE OR NOT: set if the year is a trailing year or not

                    childButton.IsInactive = (year <decade || year> decadeEnd);
                }
                else
                {
                    childButton.IsEnabled = false;
                    childButton.Opacity   = 0;
                }

                count++;
            }
        }
Beispiel #3
0
 private void Month_MouseLeave(object sender, MouseEventArgs e)
 {
     if (_isMouseLeftButtonDownYearView)
     {
         CalendarButton b = sender as CalendarButton;
         //The button is in Pressed state. Change the state to normal.
         b.ReleaseMouseCapture();
         if (_downEventArgYearView != null)
         {
             b.SendMouseUpEvent(_downEventArgYearView);
         }
         this._lastCalendarButton = b;
     }
 }
Beispiel #4
0
        private void Month_CalendarButtonMouseDown(object sender, MouseButtonEventArgs e)
        {
            CalendarButton b = sender as CalendarButton;

            Debug.Assert(b != null);

            this._isMouseLeftButtonDownYearView = true;

            if (e != null)
            {
                _downEventArgYearView = e;
            }

            UpdateYearViewSelection(b);
        }
Beispiel #5
0
        private void SetMonthButtonsForYearMode()
        {
            int count = 0;

            foreach (object child in _yearView.Children)
            {
                CalendarButton childButton = child as CalendarButton;
                Debug.Assert(childButton != null);
                //There should be no time component. Time is 12:00 AM
                DateTime day = new DateTime(_currentMonth.Year, count + 1, 1);
                childButton.DataContext = day;

                childButton.Content    = DateTimeHelper.GetCurrentDateFormat().AbbreviatedMonthNames[count];
                childButton.Visibility = Visibility.Visible;

                if (this.Owner != null)
                {
                    if (day.Year == _currentMonth.Year && day.Month == _currentMonth.Month && day.Day == _currentMonth.Day)
                    {
                        this.Owner.FocusCalendarButton = childButton;
                        childButton.IsFocusedOverride  = this.Owner._hasFocus;
                    }
                    else
                    {
                        childButton.IsFocusedOverride = false;
                    }

                    Debug.Assert(this.Owner.DisplayDateInternal != null);
                    childButton.IsSelected = (DateTimeHelper.CompareYearMonth(day, this.Owner.DisplayDateInternal) == 0);

                    if (DateTimeHelper.CompareYearMonth(day, this.Owner.DisplayDateRangeStart) < 0 || DateTimeHelper.CompareYearMonth(day, this.Owner.DisplayDateRangeEnd) > 0)
                    {
                        childButton.IsEnabled = false;
                        childButton.Opacity   = 0;
                    }
                    else
                    {
                        childButton.IsEnabled = true;
                        childButton.Opacity   = 1;
                    }
                }

                childButton.IsInactive = false;
                count++;
            }
        }
Beispiel #6
0
        internal void UpdateYearViewSelection(CalendarButton calendarButton)
        {
            if (this.Owner != null && calendarButton != null && calendarButton.DataContext != null)
            {
                this.Owner.FocusCalendarButton.IsFocusedOverride = false;
                this.Owner.FocusCalendarButton   = calendarButton;
                calendarButton.IsFocusedOverride = this.Owner._hasFocus;

                if (this.Owner.DisplayMode == CalendarMode.Year)
                {
                    this.Owner.SelectedMonth = (DateTime)calendarButton.DataContext;
                }
                else
                {
                    this.Owner.SelectedYear = (DateTime)calendarButton.DataContext;
                }
            }
        }
Beispiel #7
0
        private void PopulateGrids() 
        {
            if (_monthView != null)
            {
                for (int i = 0; i < COLS; i++) 
                {
                    FrameworkElement titleCell = (this._dayTitleTemplate != null) ? (FrameworkElement)this._dayTitleTemplate.LoadContent() : new ContentControl(); 
                    titleCell.SetValue(Grid.RowProperty, 0); 
                    titleCell.SetValue(Grid.ColumnProperty, i);
                    this._monthView.Children.Add(titleCell); 
                }

                for (int i = 1; i < ROWS; i++)
                { 
                    for (int j = 0; j < COLS; j++)
                    { 
                        CalendarDayButton dayCell = new CalendarDayButton(); 

                        dayCell.Owner = this.Owner; 
                        dayCell.SetValue(Grid.RowProperty, i);
                        dayCell.SetValue(Grid.ColumnProperty, j);
                        dayCell.SetBinding(CalendarDayButton.StyleProperty, GetOwnerBinding("CalendarDayButtonStyle"));
 
                        dayCell.AddHandler(CalendarDayButton.MouseLeftButtonDownEvent, new MouseButtonEventHandler(Cell_MouseLeftButtonDown), true);
                        dayCell.AddHandler(CalendarDayButton.MouseLeftButtonUpEvent, new MouseButtonEventHandler(Cell_MouseLeftButtonUp), true); 
                        dayCell.AddHandler(CalendarDayButton.MouseEnterEvent, new MouseEventHandler(Cell_MouseEnter), true); 
                        dayCell.Click += new RoutedEventHandler(Cell_Clicked);
                        dayCell.AddHandler(PreviewKeyDownEvent, new RoutedEventHandler(CellOrMonth_PreviewKeyDown), true); 

                        this._monthView.Children.Add(dayCell);
                    }
                } 
            }
 
            if (_yearView != null) 
            {
                CalendarButton monthCell; 
                int count = 0;
                for (int i = 0; i < YEAR_ROWS; i++)
                {
                    for (int j = 0; j < YEAR_COLS; j++) 
                    {
                        monthCell = new CalendarButton(); 
 
                        monthCell.Owner = this.Owner;
                        monthCell.SetValue(Grid.RowProperty, i); 
                        monthCell.SetValue(Grid.ColumnProperty, j);
                        monthCell.SetBinding(CalendarButton.StyleProperty, GetOwnerBinding("CalendarButtonStyle"));

                        monthCell.AddHandler(CalendarButton.MouseLeftButtonDownEvent, new MouseButtonEventHandler(Month_MouseLeftButtonDown), true); 
                        monthCell.AddHandler(CalendarButton.MouseLeftButtonUpEvent, new MouseButtonEventHandler(Month_MouseLeftButtonUp), true);
                        monthCell.AddHandler(CalendarButton.MouseEnterEvent, new MouseEventHandler(Month_MouseEnter), true); 
                        monthCell.AddHandler(UIElement.PreviewKeyDownEvent, new RoutedEventHandler(CellOrMonth_PreviewKeyDown), true); 
                        monthCell.Click += new RoutedEventHandler(Month_Clicked);
 
                        this._yearView.Children.Add(monthCell);
                        count++;
                    }
                } 
            }
        } 
        /// <summary>
        /// Inherited code: Requires comment.
        /// </summary>
        /// <param name="calendarButton">Inherited code: Requires comment 1.</param>
        internal void UpdateYearViewSelection(CalendarButton calendarButton)
        {
            if (Owner != null && calendarButton != null && calendarButton.DataContext != null)
            {
                Owner.FocusCalendarButton.IsCalendarButtonFocused = false;
                Owner.FocusCalendarButton = calendarButton;
                calendarButton.IsCalendarButtonFocused = Owner.HasFocusInternal;

                if (Owner.DisplayMode == CalendarMode.Year)
                {
                    Owner.SelectedMonth = (DateTime) calendarButton.DataContext;
                }
                else
                {
                    Owner.SelectedYear = (DateTime) calendarButton.DataContext;
                }
            }
        }
        /// <summary>
        /// Inherited code: Requires comment.
        /// </summary>
        private void PopulateGrids()
        {
            if (MonthView != null)
            {
                for (int i = 0; i < Calendar.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 < Calendar.RowsPerMonth; i++)
                {
                    for (int j = 0; j < Calendar.ColumnsPerMonth; j++)
                    {
                        CalendarDayButton cell = new CalendarDayButton();

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

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

                        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 += new MouseButtonEventHandler(Month_CalendarButtonMouseDown);
                        month.CalendarButtonMouseUp += new MouseButtonEventHandler(Month_CalendarButtonMouseUp);
                        month.MouseEnter += new MouseEventHandler(Month_MouseEnter);
                        month.MouseLeave += new MouseEventHandler(Month_MouseLeave);
                        YearView.Children.Add(month);
                        count++;
                    }
                }
            }
        }
 /// <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)
     {
         CalendarButton b = sender as CalendarButton;
         // The button is in Pressed state. Change the state to normal.
         b.ReleaseMouseCapture();
         if (_downEventArgYearView != null)
         {
             b.SendMouseLeftButtonUp(_downEventArgYearView);
         }
         _lastCalendarButton = b;
     }
 }
Beispiel #11
0
        internal void UpdateYearViewSelection(CalendarButton calendarButton)
        {
            if (this.Owner != null && calendarButton!= null && calendarButton.DataContext != null)
            {
                this.Owner.FocusCalendarButton.IsFocusedOverride = false;
                this.Owner.FocusCalendarButton = calendarButton;
                calendarButton.IsFocusedOverride = this.Owner._hasFocus;

                if (this.Owner.DisplayMode == CalendarMode.Year)
                {
                    this.Owner.SelectedMonth = (DateTime)calendarButton.DataContext;
                }
                else
                {
                    this.Owner.SelectedYear = (DateTime)calendarButton.DataContext;
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the AutomationPeer for CalendarButton.
        /// </summary>
        /// <param name="owner">CalendarButton</param>
        public CalendarButtonAutomationPeer(CalendarButton owner)
            : base(owner)
        {

        }
Beispiel #13
0
        internal void OnCalendarButtonPressed(CalendarButton b, bool switchDisplayMode) 
        {
            if (b.DataContext is DateTime) 
            { 
                DateTime d = (DateTime)b.DataContext;
 
                DateTime? newDate = null;
                CalendarMode newMode = CalendarMode.Month;

                switch (this.DisplayMode) 
                {
                    case CalendarMode.Month: 
                    { 
                        Debug.Assert(false);
                        break; 
                    }

                    case CalendarMode.Year:
                    { 
                        newDate = DateTimeHelper.SetYearMonth(this.DisplayDate, d);
                        newMode = CalendarMode.Month; 
                        break; 
                    }
 
                    case CalendarMode.Decade:
                    {
                        newDate = DateTimeHelper.SetYear(this.DisplayDate, d.Year);
                        newMode = CalendarMode.Year; 
                        break;
                    } 
 
                    default:
                        Debug.Assert(false); 
                        break;
                }

                if (newDate.HasValue) 
                {
                    this.DisplayDate = newDate.Value; 
                    if (switchDisplayMode) 
                    {
                        this.SetCurrentValueInternal(DisplayModeProperty, newMode); 
                        FocusDate(this.DisplayMode == CalendarMode.Month ? this.CurrentDate : this.DisplayDate);
                    }
                }
            } 
        }
Beispiel #14
0
        private static void EnsureCalendarButtonStyle(CalendarButton calendarButton, Style oldCalendarButtonStyle, Style newCalendarButtonStyle)
        {
            Debug.Assert(calendarButton != null);

            if (newCalendarButtonStyle != null)
            {
                // 

                if (calendarButton != null && (calendarButton.Style == null || calendarButton.Style == oldCalendarButtonStyle))
                {
                    calendarButton.Style = newCalendarButtonStyle;
                }
            }
        }
Beispiel #15
0
        private void PopulateGrids()
        {
            if (_monthView != null)
            {
                for (int i = 0; i < COLS; i++)
                {
                    if (_dayTitleTemplate != null)
                    {
                        FrameworkElement cell = (FrameworkElement)this._dayTitleTemplate.LoadContent();
                        cell.SetValue(Grid.RowProperty, 0);
                        cell.SetValue(Grid.ColumnProperty, i);
                        this._monthView.Children.Add(cell);
                    }
                }

                for (int i = 1; i < ROWS; i++)
                {
                    for (int j = 0; j < COLS; j++)
                    {
                        CalendarDayButton cell = new CalendarDayButton();

                        if (this.Owner != null)
                        {
                            cell.Owner = this.Owner;
                            if (this.Owner.CalendarDayButtonStyle != null)
                            {
                                cell.Style = this.Owner.CalendarDayButtonStyle;
                            }
                        }
                        cell.SetValue(Grid.RowProperty, i);
                        cell.SetValue(Grid.ColumnProperty, j);
                        cell.CalendarDayButtonMouseDown += new MouseButtonEventHandler(Cell_MouseLeftButtonDown);
                        cell.CalendarDayButtonMouseUp   += new MouseButtonEventHandler(Cell_MouseLeftButtonUp);
                        cell.MouseEnter += new MouseEventHandler(Cell_MouseEnter);
                        cell.MouseLeave += new MouseEventHandler(Cell_MouseLeave);
                        cell.Click      += new RoutedEventHandler(Cell_Click);
                        this._monthView.Children.Add(cell);
                    }
                }
            }

            if (_yearView != null)
            {
                CalendarButton month;
                int            count = 0;
                for (int i = 0; i < YEAR_ROWS; i++)
                {
                    for (int j = 0; j < YEAR_COLS; j++)
                    {
                        month = new CalendarButton();

                        if (this.Owner != null)
                        {
                            month.Owner = this.Owner;
                            if (this.Owner.CalendarButtonStyle != null)
                            {
                                month.Style = this.Owner.CalendarButtonStyle;
                            }
                        }
                        month.SetValue(Grid.RowProperty, i);
                        month.SetValue(Grid.ColumnProperty, j);
                        month.CalendarButtonMouseDown += new MouseButtonEventHandler(Month_CalendarButtonMouseDown);
                        month.CalendarButtonMouseUp   += new MouseButtonEventHandler(Month_CalendarButtonMouseUp);
                        month.MouseEnter += new MouseEventHandler(Month_MouseEnter);
                        month.MouseLeave += new MouseEventHandler(Month_MouseLeave);
                        this._yearView.Children.Add(month);
                        count++;
                    }
                }
            }
        }
        /// <summary>
        /// Inherited code: Requires comment.
        /// </summary>
        /// <param name="calendarButton">Inherited code: Requires comment 1.</param>
        /// <param name="oldCalendarButtonStyle">Inherited code: Requires comment 2.</param>
        /// <param name="newCalendarButtonStyle">Inherited code: Requires comment 3.</param>
        private static void EnsureCalendarButtonStyle(CalendarButton calendarButton, Style oldCalendarButtonStyle, Style newCalendarButtonStyle)
        {
            Debug.Assert(calendarButton != null, "The calendarButton should not be null!");

            if (newCalendarButtonStyle != null)
            {
                // REMOVE_RTM: Remove null check when Silverlight allows us to re-apply styles
                // Apply the newCalendarButtonStyle if the CalendarButton was
                // using the oldCalendarButtonStyle before
                if (calendarButton != null && (calendarButton.Style == null || calendarButton.Style == oldCalendarButtonStyle))
                {
                    calendarButton.Style = newCalendarButtonStyle;
                }
            }
        }