/// <summary> /// Returns the text label of the CalendarDayButton that is associated /// with this CalendarDayButtonAutomationPeer. 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(); } CalendarExDayButton button = OwningCalendarDayButton; if (string.IsNullOrEmpty(name) && button != null) { if (button.DataContext is DateTime) { name = ((DateTime)button.DataContext).ToLongDateString(); } else if (button.Content != null) { name = string.Format(DateTimeHelper.GetCurrentDateFormat(), button.Content.ToString()); } } } return(name); }
/// <summary> /// Raise an automation peer event for the selection of a day button. /// </summary> /// <param name="calendar"> /// The Calendar 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(CalendarEx calendar, DateTime date, AutomationEvents eventToRaise) { CalendarExDayButton button = calendar.FindDayButtonFromDay(date); if (button != null) { AutomationPeer peer = FrameworkElementAutomationPeer.FromElement(button); if (peer != null) { peer.RaiseAutomationEvent(eventToRaise); } } }
/// <summary> /// Clear any existing selection and then selects the current element. /// </summary> void ISelectionItemProvider.Select() { if (EnsureSelection()) { CalendarEx calendar = OwningCalendar; CalendarExDayButton button = OwningCalendarDayButton; calendar.SelectedDates.Clear(); if (button.DataContext != null) { calendar.SelectedDates.Add((DateTime)button.DataContext); } } }
/// <summary> /// Returns the string that describes the functionality of the /// CalendarDayButton that is associated with this /// CalendarDayButtonAutomationPeer. 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() { CalendarExDayButton button = OwningCalendarDayButton; if (button != null && button.DataContext != null && button.DataContext is DateTime) { DateTime dataContext = (DateTime)OwningCalendarDayButton.DataContext; Globalization.DateTimeFormatInfo info = DateTimeHelper.GetCurrentDateFormat(); return(!button.IsBlackout ? dataContext.Date.ToString(info.LongDatePattern, info) : string.Format(info, System.Windows.Controls.Properties.Resources.CalendarAutomationPeer_BlackoutDayHelpText, dataContext.Date.ToString(info.LongDatePattern, info))); } return(base.GetHelpTextCore()); }
/// <summary> /// Removes the current element from the collection of selected items. /// </summary> void ISelectionItemProvider.RemoveFromSelection() { // Return if the item is not already selected. CalendarExDayButton button = OwningCalendarDayButton; if (!button.IsSelected) { return; } CalendarEx calendar = OwningCalendar; if (calendar != null && button.DataContext != null) { calendar.SelectedDates.Remove((DateTime)button.DataContext); } }
/// <summary> /// Ensure selection of the CalendarDayButton is possible. /// </summary> /// <returns> /// A value indicating whether selection of the CalendarDayButton is /// possible. /// </returns> private bool EnsureSelection() { CalendarExDayButton button = OwningCalendarDayButton; if (!button.IsEnabled) { throw new ElementNotEnabledException(); } // If the day is a blackout day or the SelectionMode is None, // selection is not allowed CalendarEx calendar = OwningCalendar; return(!button.IsBlackout && button.Visibility != Visibility.Collapsed && calendar != null && calendar.SelectionMode != CalendarExSelectionMode.None); }
/// <summary> /// Adds the current element to the collection of selected items. /// </summary> void ISelectionItemProvider.AddToSelection() { // Return if the item is already selected CalendarExDayButton button = OwningCalendarDayButton; if (button.IsSelected) { return; } CalendarEx calendar = OwningCalendar; if (EnsureSelection() && button.DataContext != null) { if (calendar.SelectionMode == CalendarExSelectionMode.SingleDate) { calendar.SelectedDate = (DateTime)button.DataContext; } else { calendar.SelectedDates.Add((DateTime)button.DataContext); } } }
/// <summary> /// Initializes a new instance of the /// <see cref="T:System.Windows.Automation.Peers.CalendarDayButtonAutomationPeer" /> /// class. /// </summary> /// <param name="owner"> /// The /// <see cref="T:System.Windows.Controls.Primitives.CalendarDayButton" /> /// instance that is associated with this /// <see cref="T:System.Windows.Automation.Peers.CalendarDayButtonAutomationPeer" />. /// </param> public CalendarExDayButtonAutomationPeer(CalendarExDayButton owner) : base(owner) { }