/// <summary> /// Adds the current element to the collection of selected items. /// </summary> void ISelectionItemProvider.AddToSelection() { // Return if the item is already selected GlobalCalendarDayButton button = OwningCalendarDayButton; if (button.IsSelected) { return; } GlobalCalendar calendar = OwningCalendar; DateTime? date = button.GetDateNullable(); if (EnsureSelection() && date != null) { if (calendar.SelectionMode == CalendarSelectionMode.SingleDate) { calendar.SelectedDate = date.Value; } else { calendar.SelectedDates.Add(date.Value); } } }
/// <summary> /// Returns a GlobalCalendarDayButton Style based on whether the day is /// a weekday or a weekend. /// </summary> /// <param name="day">The day to select a Style for.</param> /// <param name="container">The GlobalCalendarDayButton.</param> /// <returns>A Style for the GlobalCalendarDayButton.</returns> public override Style SelectStyle(DateTime day, GlobalCalendarDayButton container) { DayOfWeek d = day.DayOfWeek; return((d == DayOfWeek.Saturday || d == DayOfWeek.Sunday) ? WeekendStyle : WeekdayStyle); }
/// <summary> /// Retrieves a UI automation provider for each child element that is /// selected. /// </summary> /// <returns> /// A collection of UI automation providers. /// </returns> IRawElementProviderSimple[] ISelectionProvider.GetSelection() { List <IRawElementProviderSimple> providers = new List <IRawElementProviderSimple>(); if (OwningGrid != null) { if (OwningCalendar.DisplayMode == CalendarMode.Month && OwningCalendar.SelectedDates != null && OwningCalendar.SelectedDates.Count != 0) { // return selected DayButtons foreach (UIElement child in OwningGrid.Children) { int childRow = (int)child.GetValue(Grid.RowProperty); if (childRow != 0) { GlobalCalendarDayButton dayButton = child as GlobalCalendarDayButton; if (dayButton != null && dayButton.IsSelected) { AutomationPeer peer = CreatePeerForElement(dayButton); if (peer != null) { providers.Add(ProviderFromPeer(peer)); } } } } } else { // return the GlobalCalendarButton which has focus foreach (UIElement child in OwningGrid.Children) { GlobalCalendarButton calendarButton = child as GlobalCalendarButton; if (calendarButton != null && calendarButton.IsCalendarButtonFocused) { AutomationPeer peer = CreatePeerForElement(calendarButton); if (peer != null) { providers.Add(ProviderFromPeer(peer)); } break; } } } if (providers.Count > 0) { return(providers.ToArray()); } } return(null); }
/// <summary> /// Raise an automation peer event for the selection of a day button. /// </summary> /// <param name="calendar"> /// The GlobalCalendar associated with this automation peer. /// </param> /// <param name="date">The selected date.</param> /// <param name="eventToRaise">The selection event to raise.</param> private static void RaiseDayButtonSelectionEvent(GlobalCalendar calendar, DateTime date, AutomationEvents eventToRaise) { GlobalCalendarDayButton button = calendar.FindDayButtonFromDay(date); if (button != null) { AutomationPeer peer = FrameworkElementAutomationPeer.FromElement(button); if (peer != null) { peer.RaiseAutomationEvent(eventToRaise); } } }
/// <summary> /// Returns a GlobalCalendarDayButton Style based on whether the day is /// a holiday. /// </summary> /// <param name="day">The day to select a Style for.</param> /// <param name="container">The GlobalCalendarDayButton.</param> /// <returns>A Style for the GlobalCalendarDayButton.</returns> public override Style SelectStyle(DateTime day, GlobalCalendarDayButton container) { Holiday holiday = Holidays.Where(h => h.FallsOn(day)).FirstOrDefault(); // Use the Holiday.Title as the Tooltip string title = holiday != null ? holiday.Title : null; ToolTipService.SetToolTip(container, title); return((holiday != null) ? HolidayStyle : NormalStyle); }
/// <summary> /// Clear any existing selection and then selects the current element. /// </summary> void ISelectionItemProvider.Select() { if (EnsureSelection()) { GlobalCalendar calendar = OwningCalendar; GlobalCalendarDayButton button = OwningCalendarDayButton; calendar.SelectedDates.Clear(); DateTime?date = button.GetDateNullable(); if (date != null) { calendar.SelectedDates.Add(date.Value); } } }
/// <summary> /// Ensure selection of the GlobalCalendarDayButton is possible. /// </summary> /// <returns> /// A value indicating whether selection of the GlobalCalendarDayButton is /// possible. /// </returns> private bool EnsureSelection() { GlobalCalendarDayButton button = OwningCalendarDayButton; if (!button.IsEnabled) { throw new ElementNotEnabledException(); } // If the day is a blackout day or the SelectionMode is None, // selection is not allowed GlobalCalendar calendar = OwningCalendar; return(!button.IsBlackout && button.Visibility != Visibility.Collapsed && calendar != null && calendar.SelectionMode != CalendarSelectionMode.None); }
/// <summary> /// Removes the current element from the collection of selected items. /// </summary> void ISelectionItemProvider.RemoveFromSelection() { // Return if the item is not already selected. GlobalCalendarDayButton button = OwningCalendarDayButton; if (!button.IsSelected) { return; } GlobalCalendar calendar = OwningCalendar; DateTime? date = button.GetDateNullable(); if (calendar != null && date != null) { calendar.SelectedDates.Remove(date.Value); } }
/// <summary> /// Returns the string that describes the functionality of the /// GlobalCalendarDayButton that is associated with this /// GlobalCalendarDayButtonAutomationPeer. This method is called by /// GetHelpText. /// </summary> /// <returns> /// The help text, or String.Empty if there is no help text. /// </returns> protected override string GetHelpTextCore() { GlobalCalendarDayButton button = OwningCalendarDayButton; if (button != null && button.DataContext is DateTime) { DateTime date = OwningCalendarDayButton.GetDate(); string text = OwningCalendar.Info.DateToLongString(date); return(!button.IsBlackout ? text : string.Format( OwningCalendar.Info.DateFormatInfo, System.Windows.Controls.Properties.Resources.CalendarAutomationPeer_BlackoutDayHelpText, text)); } return(base.GetHelpTextCore()); }
/// <summary> /// Returns the text label of the GlobalCalendarDayButton that is associated /// with this GlobalCalendarDayButtonAutomationPeer. This method is called by /// GetName. /// </summary> /// <returns> /// The text label of the element that is associated with this /// automation peer. /// </returns> /// <remarks> /// The name property can be thought of as the string of text that a /// user would use to explain which control is being referred to. It is /// important to have a textual representation for all controls in the /// graphical user interface (GUI) so that you can programmatically /// refer to the control in a localized manner. The value is settable /// on control instances through the AutomationProperties.Name attached /// property. /// </remarks> protected override string GetNameCore() { string name = base.GetNameCore(); if (string.IsNullOrEmpty(name)) { AutomationPeer labeledBy = GetLabeledByCore(); if (labeledBy != null) { name = labeledBy.GetName(); } GlobalCalendarDayButton button = OwningCalendarDayButton; if (string.IsNullOrEmpty(name) && button != null && button.Content != null) { name = string.Format( OwningCalendar.Info.DateFormatInfo, button.Content.ToString()); } } return(name); }
/// <summary> /// When overridden in a derived class, returns a /// GlobalCalendarDayButton Style based on custom logic. /// </summary> /// <param name="day"> /// The day to select a Style for. /// </param> /// <param name="container"> /// The GlobalCalendarDayButton. /// </param> /// <returns> /// A Style for the GlobalCalendarDayButton. /// </returns> public abstract Style SelectStyle(DateTime day, GlobalCalendarDayButton container);
/// <summary> /// Get the date of a GlobalCalendarDayButton. /// </summary> /// <param name="button"> /// The button. /// </param> /// <returns> /// The date of the button. /// </returns> public static DateTime?GetDateNullable(this GlobalCalendarDayButton button) { Debug.Assert(button != null, "button should not be null!"); return(button.DataContext as DateTime?); }
/// <summary> /// Get the date of a GlobalCalendarDayButton. /// </summary> /// <param name="button"> /// The button. /// </param> /// <returns> /// The date of the button. /// </returns> public static DateTime GetDate(this GlobalCalendarDayButton button) { Debug.Assert(button != null, "button should not be null!"); return((DateTime)button.DataContext); }
/// <summary> /// Set the date of a GlobalCalendarDayButton. /// </summary> /// <param name="button"> /// The button. /// </param> /// <param name="date"> /// The date of the button. /// </param> public static void SetDate(this GlobalCalendarDayButton button, DateTime date) { Debug.Assert(button != null, "button should not be null!"); button.DataContext = date; }
/// <summary> /// Initializes a new instance of the /// <see cref="T:System.Windows.Automation.Peers.GlobalCalendarDayButtonAutomationPeer" /> /// class. /// </summary> /// <param name="owner"> /// The /// <see cref="T:System.Windows.Controls.Primitives.GlobalCalendarDayButton" /> /// instance that is associated with this /// <see cref="T:System.Windows.Automation.Peers.GlobalCalendarDayButtonAutomationPeer" />. /// </param> public GlobalCalendarDayButtonAutomationPeer(GlobalCalendarDayButton owner) : base(owner) { }