private void PopulateGrids() { if (_monthView != null) { if (_dayTitleTemplate != null) { for (int i = 0; i < COLS; i++) { FrameworkElement titleCell = (FrameworkElement)this._dayTitleTemplate.LoadContent(); 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.AddHandler(CalendarDayButton.MouseLeaveEvent, new MouseEventHandler(Cell_MouseLeave), true); dayCell.Click += new RoutedEventHandler(Cell_Clicked); 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.Click += new RoutedEventHandler(Month_Clicked); this._yearView.Children.Add(monthCell); count++; } } } }
private void Month_Clicked(object sender, RoutedEventArgs e) { CalendarButton b = sender as CalendarButton; if (b != null) { this.Owner.OnCalendarButtonPressed(b, true); } }
private void Month_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { CalendarButton b = sender as CalendarButton; if (b != null && this.Owner != null) { this.Owner.OnCalendarButtonPressed(b, true); } }
/// <summary> /// Common PropertyChangedCallback for dependency properties that trigger visual state changes /// </summary> /// <param name="dObject"></param> /// <param name="e"></param> private static void OnVisualStatePropertyChanged(DependencyObject dObject, DependencyPropertyChangedEventArgs e) { CalendarButton button = dObject as CalendarButton; if (button != null && !object.Equals(e.OldValue, e.NewValue)) { button.ChangeVisualState(true); } }
private IEnumerable <CalendarButton> GetCalendarButtons() { foreach (UIElement element in this.YearView.Children) { CalendarButton b = element as CalendarButton; if (b != null) { yield return(b); } } }
private void Month_MouseEnter(object sender, MouseEventArgs e) { CalendarButton b = sender as CalendarButton; if (b != null) { if (this._isMonthPressed && this.Owner != null) { this.Owner.OnCalendarButtonPressed(b, false); } } }
private static object OnCoerceContent(DependencyObject sender, object baseValue) { CalendarButton button = (CalendarButton)sender; if (button._shouldCoerceContent) { button._shouldCoerceContent = false; return(button._coercedContent); } return(baseValue); }
private void SetYearButtons(DateTime decade, DateTime decadeEnd) { int decadeYear = _calendar.GetYear(decade); int decadeEndYear = _calendar.GetYear(decadeEnd); int year; int count = -1; foreach (object child in _yearView.Children) { CalendarButton childButton = child as CalendarButton; Debug.Assert(childButton != null); year = decadeYear + count; if (year <= _calendar.MaxSupportedDateTime.Year && year >= _calendar.MinSupportedDateTime.Year) { // There should be no time component. Time is 12:00 AM DateTime day = _calendar.ToDateTime(year, 1, 1, 0, 0, 0, 0); childButton.DataContext = day; childButton.SetContentInternal(DateTimeHelper.ToYearString(day, DateTimeHelper.GetCulture(this))); childButton.Visibility = Visibility.Visible; if (Owner != null) { childButton.HasSelectedDays = (_calendar.GetYear(Owner.DisplayDate) == year); if (year < Owner.DisplayDateStartInternal.Year || year > Owner.DisplayDateEndInternal.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 <decadeYear || year> decadeEndYear; } else { childButton.DataContext = null; childButton.IsEnabled = false; childButton.Opacity = 0; } count++; } }
private void Month_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { CalendarButton b = sender as CalendarButton; if (b != null) { this._isMonthPressed = true; Mouse.Capture(this, CaptureMode.SubTree); if (this.Owner != null) { this.Owner.OnCalendarButtonPressed(b, false); } } }
private void SetYearModeMonthButtons() { 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 int year = _calendar.GetYear(DisplayDate); int month = count + 1; DateTime day = _calendar.ToDateTime(year, month, 1, 0, 0, 0, 0); childButton.DataContext = day; childButton.SetContentInternal(DateTimeHelper.ToAbbreviatedMonthString(day, DateTimeHelper.GetCulture(this))); childButton.Visibility = Visibility.Visible; if (Owner != null) { Debug.Assert(Owner.DisplayDateInternal != null); childButton.HasSelectedDays = (DateTimeHelper.CompareYearMonth(day, Owner.DisplayDateInternal) == 0); if (DateTimeHelper.CompareYearMonth(day, Owner.DisplayDateStartInternal) < 0 || DateTimeHelper.CompareYearMonth(day, Owner.DisplayDateEndInternal) > 0) { childButton.IsEnabled = false; childButton.Opacity = 0; } else { childButton.IsEnabled = true; childButton.Opacity = 1; } } childButton.IsInactive = false; count++; } }
private int GetDecadeForDecadeMode(DateTime selectedYear) { int decade = DateTimeHelper.DecadeOfDate(selectedYear); // Adjust the decade value if the mouse move selection is on, // such that if first or last year among the children are selected // then return the current selected decade as is. if (_isMonthPressed && _yearView != null) { UIElementCollection yearViewChildren = _yearView.Children; int count = yearViewChildren.Count; if (count > 0) { CalendarButton child = yearViewChildren[0] as CalendarButton; if (child != null && child.DataContext is DateTime && ((DateTime)child.DataContext).Year == selectedYear.Year) { return(decade + 10); } } if (count > 1) { CalendarButton child = yearViewChildren[count - 1] as CalendarButton; if (child != null && child.DataContext is DateTime && ((DateTime)child.DataContext).Year == selectedYear.Year) { return(decade - 10); } } } return(decade); }
private void PopulateGrids() { if (_monthView != null) { if (_dayTitleTemplate != null) { for (int i = 0; i < COLS; i++) { FrameworkElement titleCell = (FrameworkElement)this._dayTitleTemplate.LoadContent(); 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++; } } } }
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.DisplayMode = newMode; FocusDate(this.DisplayMode == CalendarMode.Month ? this.CurrentDate : this.DisplayDate); } } } }
/// <summary> /// Initializes a new instance of the CalendarButtonAutomationPeer class. /// </summary> /// <param name="owner">Owning CalendarButton</param> public CalendarButtonAutomationPeer(CalendarButton owner) : base(owner) { }