private void CalendarDayButton_MouseDoubleClick(object sender, MouseButtonEventArgs e) { System.Windows.Controls.Primitives.CalendarDayButton button = sender as System.Windows.Controls.Primitives.CalendarDayButton; Event objEvent = new Event(); DateTime clickedDate = (DateTime)button.DataContext; if (_eventDAL.GetEventList(clickedDate).Count > 0) { if (clickedDate != null) { _winService.ShowView(ViewKeys.EventList, "Event List"); _eventAggregator.GetEvent <AddEventClickedDate>().Publish(clickedDate.ToString()); } } else { if (clickedDate.Date > DateTime.Now.Date) { clickedDate = DateTime.Now; } NavigationParameters param = new NavigationParameters(); param.Add("clickedDate", clickedDate); _winService.ShowView(ViewKeys.AddEvent, "Edit Event", param); //JCHMessageBox.Show("No Event added"); } }
private void Cell_Click(object sender, RoutedEventArgs e) { if (this.Owner != null) { bool ctrl, shift; KeyboardHelper.GetMetaKeyState(out ctrl, out shift); if (ctrl && this.Owner.SelectionMode == CalendarSelectionMode.MultipleRange) { CalendarDayButton b = sender as CalendarDayButton; Debug.Assert(b != null); if (b.IsSelected) { this.Owner._hoverStart = null; this._isMouseLeftButtonDown = false; b.IsSelected = false; if (b.DataContext != null) { this.Owner.SelectedDates.Remove((DateTime)b.DataContext); } } } } }
private void Cell_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (this.Owner != null) { bool ctrl, shift; KeyboardHelper.GetMetaKeyState(out ctrl, out shift); CalendarDayButton b = sender as CalendarDayButton; if (b != null && !b.IsDisabled) { this.Owner.OnDayButtonMouseUp(e); } _isMouseLeftButtonDown = false; if (b != null && b.DataContext != null) { if (this.Owner.SelectionMode == CalendarSelectionMode.None || this.Owner.SelectionMode == CalendarSelectionMode.SingleDate) { this.Owner.OnDayClick((DateTime)b.DataContext); return; } if (this.Owner._hoverStart.HasValue) { switch (this.Owner.SelectionMode) { case CalendarSelectionMode.SingleRange: { //Update SelectedDates foreach (DateTime item in this.Owner.SelectedDates) { this.Owner._removedItems.Add(item); } this.Owner.SelectedDates.ClearInternal(); AddSelection(b); return; } case CalendarSelectionMode.MultipleRange: { //add the selection (either single day or SingleRange day) AddSelection(b); return; } } } else { //If the day is Disabled but a trailing day we should be able to switch months if (b.IsInactive && b.IsDisabled) { this.Owner.OnDayClick((DateTime)b.DataContext); } } } } }
private void Cell_MouseLeave(object sender, MouseEventArgs e) { if (_isMouseLeftButtonDown) { CalendarDayButton b = sender as CalendarDayButton; //The button is in Pressed state. Change the state to normal. b.ReleaseMouseCapture(); //null check is added for unit tests if (_downEventArg != null) { b.SendMouseUpEvent(_downEventArg); } this._lastCalendarDayButton = b; } }
private void AddSelection(CalendarDayButton b) { if (this.Owner != null) { this.Owner._hoverEndIndex = b.Index; this.Owner.HoverEnd = (DateTime)b.DataContext; if (this.Owner.HoverEnd != null && this.Owner._hoverStart != null) { //this is selection with Mouse, we do not guarantee the range does not include BlackOutDates. //AddRange method will throw away the BlackOutDates based on the SelectionMode this.Owner._isMouseSelection = true; this.Owner.SelectedDates.AddRange(this.Owner._hoverStart.Value, this.Owner.HoverEnd.Value); Owner.OnDayClick((DateTime)b.DataContext); } } }
private void Cell_MouseEnter(object sender, MouseEventArgs e) { if (this.Owner != null) { CalendarDayButton b = sender as CalendarDayButton; if (_isMouseLeftButtonDown && b != null && b.IsEnabled && !b.IsDisabled) { //Update the states of all buttons to be selected starting from // _hoverStart to b switch (this.Owner.SelectionMode) { case CalendarSelectionMode.SingleDate: { DateTime selectedDate = (DateTime)b.DataContext; this.Owner.DatePickerDisplayDateFlag = true; if (this.Owner.SelectedDates.Count == 0) { this.Owner.SelectedDates.Add(selectedDate); } else { this.Owner.SelectedDates[0] = selectedDate; } return; } case CalendarSelectionMode.SingleRange: case CalendarSelectionMode.MultipleRange: { Debug.Assert(b.DataContext != null); this.Owner.UnHighlightDays(); this.Owner._hoverEndIndex = b.Index; this.Owner.HoverEnd = (DateTime)b.DataContext; //Update the States of the buttons this.Owner.HighlightDays(); return; } } } } }
/// <summary> /// Inherited code: Requires comment. /// </summary> /// <param name="b">Inherited code: Requires comment 1.</param> private void AddSelection(CalendarDayButton b) { if (Owner != null) { Owner.HoverEndIndex = b.Index; Owner.HoverEnd = (DateTime) b.DataContext; if (Owner.HoverEnd != null && Owner.HoverStart != null) { // this is selection with Mouse, we do not guarantee the // range does not include BlackOutDates. AddRange method // will throw away the BlackOutDates based on the // SelectionMode Owner.IsMouseSelection = true; Owner.SelectedDates.AddRange(Owner.HoverStart.Value, Owner.HoverEnd.Value); Owner.OnDayClick((DateTime) b.DataContext); } } }
/// <summary> /// Inherited code: Requires comment. /// </summary> /// <param name="sender">Inherited code: Requires comment 1.</param> /// <param name="e">Inherited code: Requires comment 2.</param> internal void Cell_MouseLeave(object sender, MouseEventArgs e) { if (_isMouseLeftButtonDown) { CalendarDayButton b = sender as CalendarDayButton; // The button is in Pressed state. Change the state to normal. b.ReleaseMouseCapture(); // null check is added for unit tests if (_downEventArg != null) { b.SendMouseLeftButtonUp(_downEventArg); } _lastCalendarDayButton = b; } }
/// <summary> /// Initializes a new instance of the AutomationPeer for CalendarDayButton. /// </summary> /// <param name="owner">CalendarDayButton</param> public CalendarDayButtonAutomationPeer(CalendarDayButton owner) :base(owner) { }
private static void EnsureDayButtonStyle(CalendarDayButton dayButton, Style oldDayButtonStyle, Style newDayButtonStyle) { Debug.Assert(dayButton != null); if (newDayButtonStyle != null) { // if (dayButton != null && (dayButton.Style == null || dayButton.Style == oldDayButtonStyle)) { dayButton.Style = newDayButtonStyle; } } }
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++; } } } }
private void SetButtonState(CalendarDayButton childButton, DateTime dateToAdd) { if (this.Owner != null) { childButton.Opacity = 1; //If the day is outside the DisplayDateStart/End boundary, do not show it if (DateTimeHelper.CompareDays(dateToAdd, this.Owner.DisplayDateRangeStart) < 0 || DateTimeHelper.CompareDays(dateToAdd, this.Owner.DisplayDateRangeEnd) > 0) { childButton.IsEnabled = false; childButton.Opacity = 0; } else { //SET IF THE DAY IS SELECTABLE OR NOT if (this.Owner.BlackoutDates.Contains(dateToAdd)) { childButton.IsDisabled = true; } else { childButton.IsDisabled = false; } childButton.IsEnabled = true; //SET IF THE DAY IS INACTIVE OR NOT: set if the day is a trailing day or not childButton.IsInactive = (DateTimeHelper.CompareYearMonth(dateToAdd, this.Owner.DisplayDateInternal) != 0); //SET IF THE DAY IS TODAY OR NOT childButton.IsToday = (this.Owner.IsTodayHighlighted && dateToAdd == DateTime.Today); //SET IF THE DAY IS SELECTED OR NOT childButton.IsSelected = false; foreach (DateTime item in this.Owner.SelectedDates) { //Since we should be comparing the Date values not DateTime values, we can't use this.Owner.SelectedDates.Contains(dateToAdd) directly childButton.IsSelected |= (DateTimeHelper.CompareDays(dateToAdd, item) == 0); } //SET THE FOCUS ELEMENT if (this.Owner.LastSelectedDate != null) { if (DateTimeHelper.CompareDays(this.Owner.LastSelectedDate.Value, dateToAdd) == 0) { if (this.Owner._focusButton != null) { this.Owner._focusButton.IsCurrent = false; } this.Owner._focusButton = childButton; if (this.Owner._hasFocus) { this.Owner._focusButton.IsCurrent = true; } } else { childButton.IsCurrent = false; } } } } }
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++; } } } }
private void Cell_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (this.Owner != null) { if (!this.Owner._hasFocus) { this.Owner.Focus(); } bool ctrl, shift; KeyboardHelper.GetMetaKeyState(out ctrl, out shift); CalendarDayButton b = sender as CalendarDayButton; if (b != null) { if (b.IsEnabled && !b.IsDisabled) { DateTime selectedDate = (DateTime)b.DataContext; Debug.Assert(selectedDate != null); _isMouseLeftButtonDown = true; //null check is added for unit tests if (e != null) { _downEventArg = e; } switch (this.Owner.SelectionMode) { case CalendarSelectionMode.None: { return; } case CalendarSelectionMode.SingleDate: { this.Owner.DatePickerDisplayDateFlag = true; if (this.Owner.SelectedDates.Count == 0) { this.Owner.SelectedDates.Add(selectedDate); } else { this.Owner.SelectedDates[0] = selectedDate; } return; } case CalendarSelectionMode.SingleRange: { //Set the start or end of the selection range if (shift) { this.Owner.UnHighlightDays(); this.Owner.HoverEnd = selectedDate; this.Owner._hoverEndIndex = b.Index; this.Owner.HighlightDays(); } else { this.Owner.UnHighlightDays(); this.Owner._hoverStart = selectedDate; this.Owner._hoverStartIndex = b.Index; } return; } case CalendarSelectionMode.MultipleRange: { if (shift) { if (!ctrl) { //clear the list, set the states to default foreach (DateTime item in this.Owner.SelectedDates) { this.Owner._removedItems.Add(item); } this.Owner.SelectedDates.ClearInternal(); } this.Owner.HoverEnd = selectedDate; this.Owner._hoverEndIndex = b.Index; this.Owner.HighlightDays(); } else { if (!ctrl) { //clear the list, set the states to default foreach (DateTime item in this.Owner.SelectedDates) { this.Owner._removedItems.Add(item); } this.Owner.SelectedDates.ClearInternal(); this.Owner.UnHighlightDays(); } this.Owner._hoverStart = selectedDate; this.Owner._hoverStartIndex = b.Index; } return; } } } else { //If a click occurs on a BlackOutDay we set the HoverStart to be null this.Owner._hoverStart = null; } } } }
/// <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++; } } } }
private void SetCalendarDayButtons(DateTime firstDayOfMonth) { int lastMonthToDisplay = PreviousMonthDays(firstDayOfMonth); DateTime dateToAdd; if (DateTimeHelper.CompareYearMonth(firstDayOfMonth, DateTime.MinValue) > 0) { //DisplayDate is not equal to DateTime.MinValue //we can subtract days from the DisplayDate dateToAdd = _calendar.AddDays(firstDayOfMonth, -lastMonthToDisplay); } else { dateToAdd = firstDayOfMonth; } if (this.Owner != null && this.Owner.HoverEnd != null && this.Owner._hoverStart != null) { this.Owner._hoverEndIndex = null; this.Owner._hoverStartIndex = null; } int count = ROWS * COLS; for (int childIndex = COLS; childIndex < count; childIndex++) { CalendarDayButton childButton = _monthView.Children[childIndex] as CalendarDayButton; Debug.Assert(childButton != null); childButton.Index = childIndex; SetButtonState(childButton, dateToAdd); //Update the indexes of hoverStart and hoverEnd if (this.Owner != null && this.Owner.HoverEnd != null && this.Owner._hoverStart != null) { if (DateTimeHelper.CompareDays(dateToAdd, this.Owner.HoverEnd.Value) == 0) { this.Owner._hoverEndIndex = childIndex; } if (DateTimeHelper.CompareDays(dateToAdd, this.Owner._hoverStart.Value) == 0) { this.Owner._hoverStartIndex = childIndex; } } childButton.IsTabStop = false; childButton.Content = dateToAdd.Day.ToString(DateTimeHelper.GetCurrentDateFormat()); childButton.DataContext = dateToAdd; if (DateTime.Compare((DateTime)DateTimeHelper.DiscardTime(DateTime.MaxValue), dateToAdd) > 0) { //Since we are sure DisplayDate is not equal to DateTime.MaxValue, //it is safe to use AddDays dateToAdd = _calendar.AddDays(dateToAdd, 1); } else { //DisplayDate is equal to the DateTime.MaxValue, so there are no trailing days childIndex++; for (int i = childIndex; i < count; i++) { childButton = _monthView.Children[i] as CalendarDayButton; Debug.Assert(childButton != null); //button needs a content to occupy the necessary space for the content presenter childButton.Content = i.ToString(DateTimeHelper.GetCurrentDateFormat()); childButton.IsEnabled = false; childButton.Opacity = 0; } return; } } //If the _hoverStart or _hoverEnd could not be found on the DisplayMonth set the values of the _hoverStartIndex or _hoverEndIndex to be the // first or last day indexes on the current month if (this.Owner != null && this.Owner._hoverStart.HasValue && this.Owner._hoverEnd.HasValue) { if (!this.Owner._hoverEndIndex.HasValue) { if (DateTimeHelper.CompareDays(this.Owner._hoverEnd.Value, this.Owner._hoverStart.Value) > 0) { this.Owner._hoverEndIndex = COLS * ROWS - 1; } else { this.Owner._hoverEndIndex = COLS; } } if (!this.Owner._hoverStartIndex.HasValue) { if (DateTimeHelper.CompareDays(this.Owner._hoverEnd.Value, this.Owner._hoverStart.Value) > 0) { this.Owner._hoverStartIndex = COLS; } else { this.Owner._hoverStartIndex = COLS * ROWS - 1; } } } }
/// <summary> /// Inherited code: Requires comment. /// </summary> /// <param name="childButton">Inherited code: Requires comment 1.</param> /// <param name="dateToAdd">Inherited code: Requires comment 2.</param> private void SetButtonState(CalendarDayButton childButton, DateTime dateToAdd) { if (Owner != null) { childButton.Opacity = 1; // If the day is outside the DisplayDateStart/End boundary, do // not show it if (DateTimeHelper.CompareDays(dateToAdd, Owner.DisplayDateRangeStart) < 0 || DateTimeHelper.CompareDays(dateToAdd, Owner.DisplayDateRangeEnd) > 0) { childButton.IsEnabled = false; childButton.Opacity = 0; } else { // SET IF THE DAY IS SELECTABLE OR NOT if (Owner.BlackoutDates.Contains(dateToAdd)) { childButton.IsBlackout = true; } else { childButton.IsBlackout = false; } childButton.IsEnabled = true; // SET IF THE DAY IS INACTIVE OR NOT: set if the day is a // trailing day or not childButton.IsInactive = (DateTimeHelper.CompareYearMonth(dateToAdd, Owner.DisplayDateInternal) != 0); // SET IF THE DAY IS TODAY OR NOT childButton.IsToday = (Owner.IsTodayHighlighted && dateToAdd == DateTime.Today); // SET IF THE DAY IS SELECTED OR NOT childButton.IsSelected = false; foreach (DateTime item in Owner.SelectedDates) { // Since we should be comparing the Date values not // DateTime values, we can't use // Owner.SelectedDates.Contains(dateToAdd) directly childButton.IsSelected |= (DateTimeHelper.CompareDays(dateToAdd, item) == 0); } // SET THE FOCUS ELEMENT if (Owner.LastSelectedDate != null) { if (DateTimeHelper.CompareDays(Owner.LastSelectedDate.Value, dateToAdd) == 0) { if (Owner.FocusButton != null) { Owner.FocusButton.IsCurrent = false; } Owner.FocusButton = childButton; if (Owner.HasFocusInternal) { Owner.FocusButton.IsCurrent = true; } } else { childButton.IsCurrent = false; } } } } }
//This method highlights the days in MultiSelection mode without adding them //to the SelectedDates collection. internal void HighlightDays() { if (this.HoverEnd != null && this._hoverStart != null) { int startIndex, endIndex, i; CalendarDayButton b; DateTime? d; CalendarItem monthControl = this.MonthControl; //This assumes a contiguous set of dates: if (this._hoverEndIndex != null && this._hoverStartIndex != null) { SortHoverIndexes(out startIndex, out endIndex); for (i = startIndex; i <= endIndex; i++) { b = monthControl.MonthView.Children[i] as CalendarDayButton; b.IsSelected = true; d = b.DataContext as DateTime?; if (d.HasValue && DateTimeHelper.CompareDays(this.HoverEnd.Value, d.Value) == 0) { if (this._focusButton != null) { this._focusButton.IsCurrent = false; } b.IsCurrent = this._hasFocus; this._focusButton = b; } } } } }
private void SetMonthModeDayButtonState(CalendarDayButton childButton, DateTime? dateToAdd) { if (this.Owner != null) { if (dateToAdd.HasValue) { childButton.Visibility = Visibility.Visible; // If the day is outside the DisplayDateStart/End boundary, do not show it if (DateTimeHelper.CompareDays(dateToAdd.Value, this.Owner.DisplayDateStartInternal) < 0 || DateTimeHelper.CompareDays(dateToAdd.Value, this.Owner.DisplayDateEndInternal) > 0) { childButton.IsEnabled = false; childButton.Visibility = Visibility.Hidden; } else { childButton.IsEnabled = true; // SET IF THE DAY IS SELECTABLE OR NOT childButton.SetValue( CalendarDayButton.IsBlackedOutPropertyKey, this.Owner.BlackoutDates.Contains(dateToAdd.Value)); // SET IF THE DAY IS ACTIVE OR NOT: set if the day is a trailing day or not childButton.SetValue( CalendarDayButton.IsInactivePropertyKey, DateTimeHelper.CompareYearMonth(dateToAdd.Value, this.Owner.DisplayDateInternal) != 0); // SET IF THE DAY IS TODAY OR NOT if (DateTimeHelper.CompareDays(dateToAdd.Value, DateTime.Today) == 0) { childButton.SetValue(CalendarDayButton.IsTodayPropertyKey, true); } else { childButton.SetValue(CalendarDayButton.IsTodayPropertyKey, false); } // the child button doesn't get change notificaitons from Calendar.IsTodayHighlighted // so we need up change visual states to ensure the IsToday is up to date. childButton.NotifyNeedsVisualStateUpdate(); // SET IF THE DAY IS SELECTED OR NOT // Since we should be comparing the Date values not DateTime values, we can't use this.Owner.SelectedDates.Contains(dateToAdd) directly bool isSelected = false; foreach (DateTime item in this.Owner.SelectedDates) { isSelected |= (DateTimeHelper.CompareDays(dateToAdd.Value, item) == 0); } childButton.SetValue(CalendarDayButton.IsSelectedPropertyKey, isSelected); } } else { childButton.Visibility = Visibility.Hidden; childButton.IsEnabled = false; childButton.SetValue(CalendarDayButton.IsBlackedOutPropertyKey, false); childButton.SetValue(CalendarDayButton.IsInactivePropertyKey, true); childButton.SetValue(CalendarDayButton.IsTodayPropertyKey, false); childButton.SetValue(CalendarDayButton.IsSelectedPropertyKey, false); } } }
private void Calendar_GotFocus(object sender, RoutedEventArgs e) { Calendar c = sender as Calendar; Debug.Assert(c != null); this._hasFocus = true; switch (this.DisplayMode) { case CalendarMode.Month: { DateTime focusDate; if (this.LastSelectedDate.HasValue && DateTimeHelper.CompareYearMonth(this.DisplayDateInternal, this.LastSelectedDate.Value) == 0) { focusDate = this.LastSelectedDate.Value; } else { focusDate = this.DisplayDate; this.LastSelectedDate = this.DisplayDate; } Debug.Assert(focusDate != null); this._focusButton = FindDayButtonFromDay(focusDate); if (this._focusButton != null) { this._focusButton.IsCurrent = true; } break; } case CalendarMode.Year: case CalendarMode.Decade: { this.FocusCalendarButton.IsFocusedOverride = true; break; } } }
public override void IsOffScreen_ScrollViewer () { Control control = new CalendarDayButton (); ScrollViewer scrollViewer = new ScrollViewer () { Height = 100 }; StackPanel panel = new StackPanel (); scrollViewer.Content = panel; AutomationPeer peer = null; CreateAsyncTest (scrollViewer, () => { for (int i = 0; i < 30; i++) panel.Children.Add (new TextBlock () { Text = i.ToString () }); // Our control won't be visible, but still won't be offscreen panel.Children.Add (control); peer = FrameworkElementAutomationPeer.CreatePeerForElement (control); Assert.IsNotNull (peer, "#0"); }, () => Assert.IsFalse (peer.IsOffscreen (), "IsOffScreen #1"), () => control.Visibility = Visibility.Collapsed, () => Assert.IsTrue (peer.IsOffscreen (), "IsOffScreen #2"), () => control.Visibility = Visibility.Visible, () => Assert.IsFalse (peer.IsOffscreen (), "IsOffScreen #3") ); }
/// <summary> /// Inherited code: Requires comment. /// </summary> /// <param name="dayButton">Inherited code: Requires comment 1.</param> /// <param name="oldDayButtonStyle">Inherited code: Requires comment 2.</param> /// <param name="newDayButtonStyle">Inherited code: Requires comment 3.</param> private static void EnsureDayButtonStyle(CalendarDayButton dayButton, Style oldDayButtonStyle, Style newDayButtonStyle) { Debug.Assert(dayButton != null, "The dayButton should not be null!"); if (newDayButtonStyle != null) { // REMOVE_RTM: Remove null check when Silverlight allows us to re-apply styles // Apply the newDayButtonStyle if the DayButton was using the // oldDayButtonStyle before if (dayButton != null && (dayButton.Style == null || dayButton.Style == oldDayButtonStyle)) { dayButton.Style = newDayButtonStyle; } } }