/// <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> /// Initializes a new instance of the /// <see cref="T:System.Windows.Controls.GlobalSelectedDatesCollection"/> /// class. /// </summary> /// <param name="owner"> /// The <see cref="T:System.Windows.Controls.GlobalCalendar"/> /// associated with this object. /// </param> public GlobalSelectedDatesCollection(GlobalCalendar owner) { Debug.Assert(owner != null, "owner should not be null!"); this._owner = owner; this._addedItems = new Collection <DateTime>(); this._dispatcherThread = Thread.CurrentThread; }
/// <summary> /// Clears any existing selection and then selects the current element. /// </summary> void ISelectionItemProvider.Select() { GlobalCalendarButton button = OwningCalendarButton; if (!button.IsEnabled) { throw new ElementNotEnabledException(); } GlobalCalendar calendar = OwningCalendar; if (calendar != null && button.Visibility != Visibility.Collapsed && !button.IsCalendarButtonFocused) { foreach (GlobalCalendarButton child in calendar.MonthControl.YearView.Children) { if (child.IsCalendarButtonFocused) { child.IsCalendarButtonFocused = false; break; } } button.IsCalendarButtonFocused = true; } }
/// <summary> /// Get the CalendarItem of a GlobalCalendar. /// </summary> /// <param name="calendar">The GlobalCalendar.</param> /// <returns>The GlobalCalendar's CalendarItem.</returns> public static GlobalCalendarItem GetCalendarItem(this GlobalCalendar calendar) { Debug.Assert(calendar != null, "calendar should not be null!"); return(calendar .GetVisualDescendants() .OfType <GlobalCalendarItem>() .FirstOrDefault()); }
/// <summary> /// Initializes a new instance of the /// <see cref="T:System.Windows.Controls.GlobalCalendarBlackoutDatesCollection" /> /// class. /// </summary> /// <param name="owner"> /// The <see cref="T:System.Windows.Controls.GlobalCalendar" /> whose dates /// this object represents. /// </param> public GlobalCalendarBlackoutDatesCollection(GlobalCalendar owner) { // TODO: This assert should be replaced with an exception. Debug.Assert(owner != null, "owner should not be null!"); _owner = owner; _dispatcherThread = Thread.CurrentThread; }
/// <summary> /// Inserts an item into the collection at the specified index. /// </summary> /// <param name="index"> /// The zero-based index at which item should be inserted. /// </param> /// <param name="item"> /// The object to insert. /// </param> /// <remarks> /// This implementation raises the CollectionChanged event. /// </remarks> protected override void InsertItem(int index, DateTime item) { if (!this.IsValidThread()) { throw new NotSupportedException(Assets.Resources.ControlsStrings.CalendarCollection_MultiThreadedCollectionChangeNotSupported); } if (!this.Contains(item)) { var addedItems = new Collection <DateTime>(); if (this.CheckSelectionMode()) { if (GlobalCalendar.IsValidDateSelection(this._owner, item)) { // If the Collection is cleared since it is SingleRange // and it had another range set the index to 0 if (this._isCleared) { index = 0; this._isCleared = false; } base.InsertItem(index, item); // The event fires after SelectedDate changes if (index == 0 && !(this._owner.SelectedDate != null && this._owner.Info.Compare(this._owner.SelectedDate.Value, item) == 0)) { this._owner.SelectedDate = item; } if (!this._isRangeAdded) { addedItems.Add(item); this._owner.OnSelectedDatesCollectionChanged(new SelectionChangedEventArgs(this._owner.RemovedItems, addedItems)); this._owner.RemovedItems.Clear(); int monthDifference = this._owner.Info.GetMonthDifference(item, this._owner.DisplayDateInternal); if (monthDifference < 2 && monthDifference > -2) { this._owner.UpdateMonths(); } } else { this._addedItems.Add(item); } } else { throw new ArgumentOutOfRangeException(Assets.Resources.ControlsStrings.Calendar_OnSelectedDateChanged_InvalidValue); } } } }
/// <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> /// Sends a request to activate the control and initiate its single, /// unambiguous action. /// </summary> void IInvokeProvider.Invoke() { GlobalCalendar calendar = OwningCalendar; if (calendar != null && OwningCalendarButton.IsEnabled) { calendar.MonthControl.UpdateYearViewSelection(OwningCalendarButton); calendar.MonthControl.Month_CalendarButtonMouseUp(OwningCalendarButton, null); } else { throw new ElementNotEnabledException(); } }
/// <summary> /// Retrieves a collection of UI Automation providers that represent all /// the column headers that are associated with a table item or cell. /// </summary> /// <returns>A collection of UI Automation providers.</returns> IRawElementProviderSimple[] ITableItemProvider.GetColumnHeaderItems() { GlobalCalendar calendar = OwningCalendar; if (calendar != null && OwningCalendarAutomationPeer != null) { IRawElementProviderSimple[] headers = ((ITableProvider)CreatePeerForElement(calendar)).GetColumnHeaders(); if (headers != null) { int column = ((IGridItemProvider)this).Column; return(new IRawElementProviderSimple[] { headers[column] }); } } return(null); }
/// <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> /// Gets the control pattern for this /// <see cref="T:System.Windows.Automation.Peers.GlobalCalendarButtonAutomationPeer" />. /// </summary> /// <param name="patternInterface"> /// One of the enumeration values. /// </param> /// <returns> /// The object that implements the pattern interface, or null if the /// specified pattern interface is not implemented by this peer. /// </returns> public override object GetPattern(PatternInterface patternInterface) { if (patternInterface == PatternInterface.GridItem || patternInterface == PatternInterface.Invoke || patternInterface == PatternInterface.SelectionItem) { GlobalCalendar calendar = OwningCalendar; if (calendar != null && calendar.MonthControl != null) { return(this); } } return(base.GetPattern(patternInterface)); }
/// <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> /// Raise selection AutomationEvents when the GlobalCalendar's SelectedDates /// collection changes. /// </summary> /// <param name="e">Event arguments.</param> internal void RaiseSelectionEvents(SelectionChangedEventArgs e) { GlobalCalendar calendar = OwningCalendar; int selectedDates = calendar.SelectedDates.Count; if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected) && selectedDates == 1) { RaiseDayButtonSelectionEvent( calendar, (DateTime)e.AddedItems[0], AutomationEvents.SelectionItemPatternOnElementSelected); } else { if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementAddedToSelection)) { foreach (DateTime date in e.AddedItems) { RaiseDayButtonSelectionEvent( calendar, date, AutomationEvents.SelectionItemPatternOnElementAddedToSelection); } } if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection)) { foreach (DateTime date in e.RemovedItems) { RaiseDayButtonSelectionEvent( calendar, date, AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); } } } }
/// <summary> /// Find a button given a date. /// </summary> /// <param name="calendar">The Calendar.</param> /// <param name="day">The date to find.</param> /// <returns>The corresponding button.</returns> public static GlobalCalendarDayButton FindDayButtonFromDay(this GlobalCalendar calendar, DateTime day) { GlobalCalendarItem monthControl = calendar.GetCalendarItem(); if (monthControl != null) { Grid monthView = monthControl.GetMonthView(); if (monthView != null) { return(monthView .Children .OfType <GlobalCalendarDayButton>() .Where(b => { DateTime?d = b.DataContext as DateTime?; return d != null && CompareDates(d.Value, day); }) .FirstOrDefault()); } } return(null); }
public void BlackoutDatesSingleDay() { GlobalCalendar calendar = new GlobalCalendar(); calendar.BlackoutDates.AddDatesInPast(); calendar.SelectedDate = DateTime.Today.AddDays(-1); }
public void DisplayDateChangedEvent() { bool handled = false; GlobalCalendar calendar = new GlobalCalendar(); calendar.SelectionMode = CalendarSelectionMode.SingleDate; calendar.DisplayDateChanged += new EventHandler<GlobalCalendarDateChangedEventArgs>(delegate { handled = true; }); DateTime value = new DateTime(2000, 10, 10); calendar.DisplayDate = value; Assert.IsTrue(handled); }
public void DisplayDateRangeEnd() { GlobalCalendar calendar = new GlobalCalendar(); DateTime value = new DateTime(2000, 1, 30); calendar.DisplayDate = value; calendar.DisplayDateEnd = value; calendar.DisplayDateStart = value; Assert.IsTrue(CompareDates(calendar.DisplayDateStart.Value, value)); Assert.IsTrue(CompareDates(calendar.DisplayDateEnd.Value, value)); value = value.AddMonths(2); calendar.DisplayDateStart = value; Assert.IsTrue(CompareDates(calendar.DisplayDateStart.Value, value)); Assert.IsTrue(CompareDates(calendar.DisplayDateEnd.Value, value)); Assert.IsTrue(CompareDates(calendar.DisplayDate, value)); }
public void SelectedDateSingle() { ResetSelectedDatesChanged(); GlobalCalendar calendar = new GlobalCalendar(); calendar.SelectedDatesChanged += new EventHandler<SelectionChangedEventArgs>(OnSelectedDatesChanged); calendar.SelectionMode = CalendarSelectionMode.SingleDate; calendar.SelectedDate = DateTime.Today; Assert.IsTrue(CompareDates(calendar.SelectedDate.Value, DateTime.Today)); Assert.IsTrue(calendar.SelectedDates.Count == 1); Assert.IsTrue(CompareDates(calendar.SelectedDates[0], DateTime.Today)); Assert.IsTrue(_selectedDatesChangedCount == 1); Assert.IsTrue(_selectedDatesChangedAddedDays.Count == 1); Assert.IsTrue(_selectedDateChangedRemovedDays.Count == 0); ResetSelectedDatesChanged(); calendar.SelectedDate = DateTime.Today; Assert.IsTrue(CompareDates(calendar.SelectedDate.Value, DateTime.Today)); Assert.IsTrue(calendar.SelectedDates.Count == 1); Assert.IsTrue(CompareDates(calendar.SelectedDates[0], DateTime.Today)); Assert.IsTrue(_selectedDatesChangedCount == 0); calendar.SelectedDate = new DateTime(); calendar.ClearValue(GlobalCalendar.SelectedDateProperty); Assert.AreEqual(DependencyProperty.UnsetValue, calendar.ReadLocalValue(GlobalCalendar.SelectedDateProperty)); calendar.SelectionMode = CalendarSelectionMode.None; Assert.IsTrue(calendar.SelectedDates.Count == 0); Assert.IsNull(calendar.SelectedDate); calendar.SelectionMode = CalendarSelectionMode.SingleDate; calendar.SelectedDates.Add(DateTime.Today.AddDays(1)); Assert.IsTrue(CompareDates(calendar.SelectedDate.Value, DateTime.Today.AddDays(1))); Assert.IsTrue(calendar.SelectedDates.Count == 1); calendar.SelectedDates.Add(DateTime.Today.AddDays(2)); }
public void SetBlackoutDatesRangeDisplayStart() { GlobalCalendar calendar = new GlobalCalendar(); calendar.DisplayDateStart = DateTime.Today.AddDays(-5); calendar.BlackoutDates.Add(new CalendarDateRange(DateTime.Today.AddDays(-10), DateTime.Today.AddDays(10))); }
public void DisplayDatePropertySetValue() { GlobalCalendar calendar = new GlobalCalendar(); calendar.SelectionMode = CalendarSelectionMode.SingleDate; DateTime value = DateTime.Today.AddMonths(3); calendar.DisplayDate = value; Assert.IsTrue(CompareDates(calendar.DisplayDate, value)); }
public void AddNone() { GlobalCalendar calendar = new GlobalCalendar(); calendar.SelectionMode = CalendarSelectionMode.None; calendar.SelectedDates.Add(new DateTime()); }
/// <summary> /// Initializes a new instance of the /// <see cref="T:System.Windows.Automation.Peers.GlobalCalendarAutomationPeer" /> /// class. /// </summary> /// <param name="owner"> /// The <see cref="T:System.Windows.Controls.GlobalCalendar" /> instance to /// associate with the /// <see cref="T:System.Windows.Automation.Peers.GlobalCalendarAutomationPeer" />. /// </param> public GlobalCalendarAutomationPeer(GlobalCalendar owner) : base(owner) { }
public void SelectionModeOutOfRangeException() { GlobalCalendar calendar = new GlobalCalendar(); calendar.SelectionMode = (CalendarSelectionMode)7; }
public void SelectDayNoneInvalidOperationException() { GlobalCalendar calendar = new GlobalCalendar(); calendar.SelectionMode = CalendarSelectionMode.None; calendar.SelectedDate = new DateTime(2000, 2, 2); }
public void SelectionMode() { GlobalCalendar calendar = new GlobalCalendar { SelectionMode = CalendarSelectionMode.SingleRange }; calendar.SelectedDates.AddRange(DateTime.Today, DateTime.Today.AddDays(10)); Assert.IsTrue(calendar.SelectedDates.Count == 11); TestAsync( calendar, () => calendar.SelectionMode = CalendarSelectionMode.MultipleRange, () => Assert.IsTrue(calendar.SelectedDates.Count == 0)); }
public void SelectedDateMultipleRange() { GlobalCalendar calendar = new GlobalCalendar(); calendar.SelectionMode = CalendarSelectionMode.MultipleRange; calendar.SelectedDate = DateTime.Today; Assert.IsTrue(CompareDates(calendar.SelectedDate.Value, DateTime.Today)); Assert.IsTrue(calendar.SelectedDates.Count == 1); Assert.IsTrue(CompareDates(calendar.SelectedDates[0], DateTime.Today)); calendar.SelectedDates.Clear(); Assert.IsNull(calendar.SelectedDate); calendar.SelectedDates.AddRange(DateTime.Today, DateTime.Today.AddDays(10)); Assert.IsTrue(CompareDates(calendar.SelectedDate.Value, DateTime.Today)); Assert.IsTrue(calendar.SelectedDates.Count == 11); calendar.SelectedDates.Add(DateTime.Today); Assert.IsTrue(calendar.SelectedDates.Count == 11); }
public void SelectedDateSingleRange() { ResetSelectedDatesChanged(); GlobalCalendar calendar = new GlobalCalendar(); calendar.SelectedDatesChanged += new EventHandler<SelectionChangedEventArgs>(OnSelectedDatesChanged); calendar.SelectionMode = CalendarSelectionMode.SingleRange; calendar.SelectedDate = DateTime.Today; Assert.IsTrue(CompareDates(calendar.SelectedDate.Value, DateTime.Today)); Assert.IsTrue(calendar.SelectedDates.Count == 1); Assert.IsTrue(CompareDates(calendar.SelectedDates[0], DateTime.Today)); Assert.IsTrue(_selectedDatesChangedCount == 1); Assert.IsTrue(_selectedDatesChangedAddedDays.Count == 1); Assert.IsTrue(_selectedDateChangedRemovedDays.Count == 0); ResetSelectedDatesChanged(); calendar.SelectedDates.Clear(); Assert.IsNull(calendar.SelectedDate); ResetSelectedDatesChanged(); calendar.SelectedDates.AddRange(DateTime.Today, DateTime.Today.AddDays(10)); Assert.IsTrue(CompareDates(calendar.SelectedDate.Value, DateTime.Today)); Assert.IsTrue(calendar.SelectedDates.Count == 11); ResetSelectedDatesChanged(); calendar.SelectedDates.AddRange(DateTime.Today, DateTime.Today.AddDays(10)); Assert.IsTrue(calendar.SelectedDates.Count == 11); Assert.IsTrue(_selectedDatesChangedCount == 0); calendar.SelectedDates.AddRange(DateTime.Today.AddDays(-20), DateTime.Today); Assert.IsTrue(CompareDates(calendar.SelectedDate.Value, DateTime.Today.AddDays(-20))); Assert.IsTrue(calendar.SelectedDates.Count == 21); Assert.IsTrue(_selectedDatesChangedCount == 1); Assert.IsTrue(_selectedDatesChangedAddedDays.Count == 21); Assert.IsTrue(_selectedDateChangedRemovedDays.Count == 11); ResetSelectedDatesChanged(); calendar.SelectedDates.Add(DateTime.Today.AddDays(100)); Assert.IsTrue(CompareDates(calendar.SelectedDate.Value, DateTime.Today.AddDays(100))); Assert.IsTrue(calendar.SelectedDates.Count == 1); }
public void BlackoutDatesRange() { GlobalCalendar calendar = new GlobalCalendar(); calendar.BlackoutDates.Add(new CalendarDateRange(DateTime.Today, DateTime.Today.AddDays(10))); calendar.SelectedDate = DateTime.Today.AddDays(-1); Assert.IsTrue(CompareDates(calendar.SelectedDate.Value, DateTime.Today.AddDays(-1))); Assert.IsTrue(CompareDates(calendar.SelectedDate.Value, calendar.SelectedDates[0])); calendar.SelectedDate = DateTime.Today.AddDays(11); Assert.IsTrue(CompareDates(calendar.SelectedDate.Value, DateTime.Today.AddDays(11))); Assert.IsTrue(CompareDates(calendar.SelectedDate.Value, calendar.SelectedDates[0])); calendar.SelectedDate = DateTime.Today.AddDays(5); }
public void DisplayModeDisplayDate() { GlobalCalendar calendar = new GlobalCalendar(); TestAsync( calendar, () => calendar.DisplayMode = CalendarMode.Year, () => Assert.IsTrue(calendar.GetCalendarItem().GetHeaderButton().Content.ToString() == calendar.DisplayDate.Year.ToString(CultureInfo.InvariantCulture))); }
public void SetBlackoutDatesRange() { GlobalCalendar calendar = new GlobalCalendar(); calendar.SelectedDate = DateTime.Today.AddDays(5); calendar.BlackoutDates.Add(new CalendarDateRange(DateTime.Today, DateTime.Today.AddDays(10))); }
public void DisplayDateRangeStartOutOfRangeExceptionSelectedDate() { GlobalCalendar calendar = new GlobalCalendar(); calendar.SelectionMode = CalendarSelectionMode.SingleDate; calendar.SelectedDate = DateTime.MinValue; Assert.IsTrue(CompareDates((DateTime)calendar.SelectedDate, DateTime.MinValue)); calendar.DisplayDateStart = DateTime.MinValue.AddDays(1); Assert.IsTrue(CompareDates((DateTime)calendar.DisplayDateStart, DateTime.MinValue)); }
public void SetBlackoutDatesRangeDisplayEnd() { GlobalCalendar calendar = new GlobalCalendar(); calendar.DisplayDateEnd = DateTime.Today.AddDays(5); calendar.BlackoutDates.Add(new CalendarDateRange(DateTime.Today, DateTime.Today.AddDays(10))); }
public void DisplayModeOutOfRangeException() { GlobalCalendar calendar = new GlobalCalendar(); calendar.DisplayMode = (CalendarMode)4; }
public void DisplayDateStartEnd() { GlobalCalendar calendar = new GlobalCalendar(); calendar.SelectionMode = CalendarSelectionMode.SingleDate; calendar.DisplayDateStart = new DateTime(2005, 12, 30); DateTime value = new DateTime(2005, 12, 15); calendar.DisplayDate = value; Assert.IsTrue(CompareDates(calendar.DisplayDate, calendar.DisplayDateStart.Value)); value = new DateTime(2005, 12, 30); calendar.DisplayDate = value; Assert.IsTrue(CompareDates(calendar.DisplayDate, value)); value = DateTime.MaxValue; calendar.DisplayDate = value; Assert.IsTrue(CompareDates(calendar.DisplayDate, value)); calendar.DisplayDateEnd = new DateTime(2010, 12, 30); Assert.IsTrue(CompareDates(calendar.DisplayDate, calendar.DisplayDateEnd.Value)); }
public void DisplayModeDecadeToMonth() { GlobalCalendar calendar = new GlobalCalendar { DisplayDate = new DateTime(2000, 1, 1), DisplayDateStart = new DateTime(2000, 1, 1), DisplayDateEnd = new DateTime(2000, 1, 1), DisplayMode = CalendarMode.Decade }; GlobalCalendarItem month = null; TestAsync( calendar, () => month = calendar.GetCalendarItem(), () => Assert.IsTrue(month.GetMonthView().Visibility == Visibility.Collapsed), () => Assert.IsTrue(month.GetYearView().Visibility == Visibility.Visible), () => Assert.IsTrue(calendar.DisplayMode == CalendarMode.Decade), () => Assert.IsFalse(month.GetHeaderButton().IsEnabled), () => Assert.IsFalse(month.GetPreviousButton().IsEnabled), () => Assert.IsFalse(month.GetNextButton().IsEnabled), () => calendar.DisplayMode = CalendarMode.Month, () => Assert.IsTrue(month.GetHeaderButton().IsEnabled), () => Assert.IsFalse(month.GetPreviousButton().IsEnabled), () => Assert.IsFalse(month.GetNextButton().IsEnabled), () => Assert.IsTrue(calendar.DisplayMode == CalendarMode.Month), () => Assert.IsTrue(month.GetMonthView().Visibility == Visibility.Visible), () => Assert.IsTrue(month.GetYearView().Visibility == Visibility.Collapsed), () => calendar.DisplayMode = CalendarMode.Year, () => Assert.IsTrue(month.GetMonthView().Visibility == Visibility.Collapsed), () => Assert.IsTrue(month.GetYearView().Visibility == Visibility.Visible)); }
public void DisplayDateRangeEndSelectedDate() { GlobalCalendar calendar = new GlobalCalendar(); calendar.SelectionMode = CalendarSelectionMode.SingleDate; calendar.SelectedDate = DateTime.MaxValue; Assert.IsTrue(CompareDates((DateTime)calendar.SelectedDate, DateTime.MaxValue)); calendar.DisplayDateEnd = DateTime.MaxValue.AddDays(-1); Assert.IsTrue(CompareDates((DateTime)calendar.DisplayDateEnd, DateTime.MaxValue)); }
public void DisplayModeDecadeDisplayDate() { GlobalCalendar calendar = new GlobalCalendar(); TestAsync( calendar, () => calendar.DisplayMode = CalendarMode.Decade, () => Assert.IsTrue(calendar.DisplayMode == CalendarMode.Decade)); }
public void DisplayDateRangeEndBlackoutDayEnd() { GlobalCalendar calendar = new GlobalCalendar(); calendar.SelectionMode = CalendarSelectionMode.SingleDate; calendar.BlackoutDates.Add(new CalendarDateRange(DateTime.Today, DateTime.Today.AddDays(4))); calendar.DisplayDateEnd = DateTime.Today; }
public void ArePropertiesNullable() { GlobalCalendar calendar = new GlobalCalendar(); DateTime value = DateTime.Today; calendar.SelectedDate = null; Assert.IsNull(calendar.SelectedDate); calendar.SelectedDate = value; Assert.IsTrue(CompareDates(value, calendar.SelectedDate.Value)); calendar.SelectedDate = null; Assert.IsNull(calendar.SelectedDate); calendar.DisplayDateStart = null; Assert.IsNull(calendar.DisplayDateStart); calendar.DisplayDateStart = value; Assert.IsTrue(CompareDates(value, calendar.DisplayDateStart.Value)); calendar.DisplayDateStart = null; Assert.IsNull(calendar.DisplayDateStart); calendar.DisplayDateEnd = null; Assert.IsNull(calendar.DisplayDateEnd); calendar.DisplayDateEnd = value; Assert.IsTrue(CompareDates(value, calendar.DisplayDateEnd.Value)); calendar.DisplayDateEnd = null; Assert.IsNull(calendar.DisplayDateEnd); GlobalCalendarItem item = null; TestAsync( calendar, () => item = calendar.GetCalendarItem(), () => Assert.IsTrue(item.GetPreviousButton().IsEnabled), () => Assert.IsTrue(item.GetNextButton().IsEnabled), () => Assert.IsTrue(item.GetHeaderButton().IsEnabled), () => Assert.IsTrue(item.GetHeaderButton().Content.ToString() == calendar.DisplayDate.ToString("Y", GlobalCalendarTestExtensions.GetCurrentDateFormat()))); }
public void DisplayModeYearToDecade() { GlobalCalendar calendar = new GlobalCalendar { DisplayMode = CalendarMode.Year }; GlobalCalendarItem month = null; TestAsync( 25, calendar, () => month = calendar.GetCalendarItem(), () => Assert.IsTrue(month.GetMonthView().Visibility == Visibility.Collapsed), () => Assert.IsTrue(month.GetYearView().Visibility == Visibility.Visible), () => Assert.IsTrue(calendar.DisplayMode == CalendarMode.Year), () => month.GetHeaderButton().ClickViaPeer(), ////() => month.HeaderButton_Click(month.GetHeaderButton(), new RoutedEventArgs()), () => Assert.IsTrue(calendar.DisplayMode == CalendarMode.Decade)); }
public void SetToMinValue() { GlobalCalendar calendar = new GlobalCalendar(); calendar.DisplayDate = DateTime.MinValue; Assert.IsTrue(CompareDates(calendar.DisplayDate, DateTime.MinValue)); calendar.DisplayDateStart = DateTime.MinValue; calendar.DisplayDateEnd = DateTime.MinValue; Assert.IsTrue(CompareDates(calendar.DisplayDateStart.Value, DateTime.MinValue)); Assert.IsTrue(CompareDates(calendar.DisplayDateEnd.Value, DateTime.MinValue)); calendar.SelectedDate = DateTime.MinValue; Assert.IsTrue(CompareDates(DateTime.MinValue, (DateTime)calendar.SelectedDate)); Assert.IsTrue(calendar.SelectedDates.Count == 1); Assert.IsTrue(CompareDates(calendar.SelectedDates[0], calendar.SelectedDate.Value)); calendar.SelectedDates.Clear(); calendar.BlackoutDates.Add(new CalendarDateRange(DateTime.MinValue)); Assert.IsTrue(CompareDates(calendar.BlackoutDates[0].End, DateTime.MinValue)); Assert.IsTrue(CompareDates(calendar.BlackoutDates[0].Start, DateTime.MinValue)); GlobalCalendarItem item = null; TestAsync( calendar, () => item = calendar.GetCalendarItem(), () => Assert.IsFalse(item.GetPreviousButton().IsEnabled), () => Assert.IsFalse(item.GetNextButton().IsEnabled), () => Assert.IsTrue(item.GetHeaderButton().IsEnabled), () => Assert.IsTrue(item.GetHeaderButton().Content.ToString() == calendar.DisplayDate.ToString("Y", GlobalCalendarTestExtensions.GetCurrentDateFormat()))); }
public void AddSingle() { GlobalCalendar calendar = new GlobalCalendar(); calendar.SelectionMode = CalendarSelectionMode.SingleDate; calendar.SelectedDates.Add(DateTime.Today); calendar.SelectedDates.Add(DateTime.Today.AddDays(1)); }
public void DateSelectedEvent() { bool handled = false; GlobalCalendar calendar = new GlobalCalendar(); calendar.SelectionMode = CalendarSelectionMode.SingleDate; calendar.SelectedDatesChanged += new EventHandler<SelectionChangedEventArgs>(delegate { handled = true; }); DateTime value = new DateTime(2000, 10, 10); calendar.SelectedDate = value; Assert.IsTrue(handled); Assert.AreEqual(calendar.ToString(), value.ToString()); }
/// <summary> /// Replaces the element at the specified index. /// </summary> /// <param name="index"> /// The zero-based index of the element to replace. /// </param> /// <param name="item"> /// The new value for the element at the specified index. /// </param> /// <remarks> /// This implementation raises the CollectionChanged event. /// </remarks> protected override void SetItem(int index, DateTime item) { if (!this.IsValidThread()) { throw new NotSupportedException(Assets.Resources.ControlsStrings.CalendarCollection_MultiThreadedCollectionChangeNotSupported); } if (!this.Contains(item)) { var addedItems = new Collection <DateTime>(); var removedItems = new Collection <DateTime>(); if (index >= this.Count) { base.SetItem(index, item); } else { if (item != null && this._owner.Info.Compare(this[index], item) != 0 && GlobalCalendar.IsValidDateSelection(this._owner, item)) { removedItems.Add(this[index]); base.SetItem(index, item); addedItems.Add(item); // The event fires after SelectedDate changes if (index == 0 && !(this._owner.SelectedDate != null && this._owner.Info.Compare(this._owner.SelectedDate.Value, item) == 0)) { this._owner.SelectedDate = item; } this._owner.OnSelectedDatesCollectionChanged(new SelectionChangedEventArgs(removedItems, addedItems)); int monthDifference = this._owner.Info.GetMonthDifference(item, this._owner.DisplayDateInternal); if (monthDifference < 2 && monthDifference > -2) { this._owner.UpdateMonths(); } } } } }
public void Create() { GlobalCalendar calendar = new GlobalCalendar(); Assert.IsNotNull(calendar); }
/// <summary> /// Adds all the dates in the specified range, which includes the first /// and last dates, to the collection. /// </summary> /// <param name="start"> /// The first date to add to the collection. /// </param> /// <param name="end"> /// The last date to add to the collection. /// </param> public void AddRange(DateTime start, DateTime end) { // increment parameter specifies if the Days were selected in // Descending order or Ascending order based on this value, we add // the days in the range either in Ascending order or in Descending // order int increment = (this._owner.Info.Compare(end, start) >= 0) ? 1 : -1; this._addedItems.Clear(); DateTime?rangeStart = start; this._isRangeAdded = true; if (this._owner.IsMouseSelection) { // In Mouse Selection we allow the user to be able to add // multiple ranges in one action in MultipleRange Mode. In // SingleRange Mode, we only add the first selected range. while (rangeStart != null && this._owner.Info.Compare(end, rangeStart.Value) != -increment) { if (GlobalCalendar.IsValidDateSelection(this._owner, rangeStart)) { this.Add(rangeStart.Value); } else if (this._owner.SelectionMode == CalendarSelectionMode.SingleRange) { this._owner.HoverEnd = this._owner.Info.AddDays(rangeStart.Value, -increment); break; } rangeStart = this._owner.Info.AddDays(rangeStart.Value, increment); } } else { // If CalendarSelectionMode.SingleRange and a user // programmatically tries to add multiple ranges, we will throw // away the old range and replace it with the new one. In order // to provide the removed items without an additional event, we // are calling ClearInternal if (this._owner.SelectionMode == CalendarSelectionMode.SingleRange && this.Count > 0) { foreach (var item in this) { this._owner.RemovedItems.Add(item); } this.ClearInternal(); } while (rangeStart != null && this._owner.Info.Compare(end, rangeStart.Value) != -increment) { this.Add(rangeStart.Value); rangeStart = this._owner.Info.AddDays(rangeStart.Value, increment); } } this._owner.OnSelectedDatesCollectionChanged(new SelectionChangedEventArgs(this._owner.RemovedItems, this._addedItems)); this._owner.RemovedItems.Clear(); this._owner.UpdateMonths(); this._isRangeAdded = false; }
public void CheckDefaultValues() { GlobalCalendar calendar = new GlobalCalendar(); Assert.IsTrue(CompareDates(DateTime.Today, calendar.DisplayDate)); Assert.IsNull(calendar.DisplayDateStart); Assert.IsNull(calendar.DisplayDateEnd); Assert.AreEqual(calendar.FirstDayOfWeek, GlobalCalendarTestExtensions.GetCurrentDateFormat().FirstDayOfWeek); Assert.IsTrue(calendar.IsTodayHighlighted); Assert.IsNull(calendar.SelectedDate); Assert.IsTrue(calendar.SelectedDates.Count == 0); Assert.IsTrue(calendar.BlackoutDates.Count == 0); Assert.IsTrue(calendar.IsEnabled); Assert.IsTrue(calendar.DisplayMode == CalendarMode.Month); Assert.IsTrue(calendar.SelectionMode == CalendarSelectionMode.SingleDate); GlobalCalendarItem item = null; TestAsync( calendar, () => item = calendar.GetCalendarItem(), () => Assert.IsTrue(item.GetPreviousButton().IsEnabled), () => Assert.IsTrue(item.GetNextButton().IsEnabled), () => Assert.IsTrue(item.GetHeaderButton().IsEnabled), () => Assert.IsTrue(item.GetHeaderButton().Content.ToString() == calendar.DisplayDate.ToString("Y", GlobalCalendarTestExtensions.GetCurrentDateFormat()))); }