/// <summary>
        /// Initializes a new instance of the <see cref="SchedulerViewModel"/> class.
        /// </summary>
        /// <param name="scheduler">The scheduler.</param>
        /// <exception cref="ArgumentNullException">scheduler</exception>
        internal SchedulerViewModel(IScheduler scheduler)
        {
            if (scheduler == null)
            {
                throw new ArgumentNullException("scheduler");
            }
            this.scheduler = scheduler;
            scheduler.ActiveViewDefinitionChanged += this.OnViewModeChanged;

            this.dayTimeSlotsView           = new TimeSlotCollectionView();
            this.dayTimeSlotsView.Scheduler = this.Scheduler as RadScheduler;
            this.activeViewDefinition       = scheduler.ActiveViewDefinition;
            this.activeViewDefinition.ViewDefinitionChanged += this.OnViewDefinitionChanged;

            this.allDayTimeSlotsView        = new TimeSlotCollectionView();
            this.allDayActiveViewDefinition = new SingleMonthWeekViewDefinition(this.activeViewDefinition);
            this.allDayTimeSlotsView.GroupDescriptions.AddRange(this.allDayActiveViewDefinition.GroupDescriptions);

            scheduler.SelectedTimeSlot = new TimeSlot(DateTime.Today, TimeSpan.FromDays(1));
            this.startDate             = this.GetStartDateForViewDefinition(
                this.activeViewDefinition,
                scheduler.SelectedTimeSlot.Start);

            this.RecreateTimeSlots();
        }
Exemple #2
0
        /// <summary>
        /// Provides derived classes an opportunity to handle changes to the <see cref="Scheduler" /> property.
        /// </summary>
        /// <param name="args">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        protected virtual void OnSchedulerChanged(DependencyPropertyChangedEventArgs args)
        {
            var scheduler = args.NewValue as IScheduler;

            if (scheduler != null && this.scrollBar != null)
            {
                ViewDefinitionBase viewDefinition = scheduler.ActiveViewDefinition;

                this.scrollBar.SmallChange =
                    viewDefinition.SmallChangeInterval.GetApproximateTotalDays(scheduler.GetCultureInUse().Calendar);
                this.scrollBar.LargeChange =
                    viewDefinition.LargeChangeInterval.GetApproximateTotalDays(scheduler.GetCultureInUse().Calendar);
                this.scrollBar.ViewportSize = 2 * this.scrollBar.LargeChange;
            }
        }
 private static TimeSlot GetSelectedTimeSlotForViewDefinition(ViewDefinitionBase definition, TimeSlot slot)
 {
     if (definition is MonthViewDefinition)
     {
         return(new TimeSlot(
                    new DateTime(slot.Start.Year, slot.Start.Month, slot.Start.Day),
                    TimeSpan.FromDays(1)));
     }
     if (definition is WeekViewDefinition)
     {
         return(new TimeSlot(
                    new DateTime(slot.Start.Year, slot.Start.Month, slot.Start.Day),
                    TimeSpan.FromDays(1)));
     }
     return(slot);
 }
        private void OnViewModeChanged(object sender, EventArgs e)
        {
            ViewDefinitionBase newDefinition = this.scheduler.ActiveViewDefinition;

            if (this.activeViewDefinition != newDefinition)
            {
                this.startDate = this.GetStartDateForViewDefinition(newDefinition, this.scheduler.SelectedTimeSlot.Start);
                this.activeViewDefinition.ViewDefinitionChanged -= this.OnViewDefinitionChanged;
                this.activeViewDefinition = this.scheduler.ActiveViewDefinition;
                this.allDayActiveViewDefinition.ActiveViewDefinition = this.activeViewDefinition;
                this.activeViewDefinition.ViewDefinitionChanged     += this.OnViewDefinitionChanged;
                TimeSlot selectedTimeSlot = GetSelectedTimeSlotForViewDefinition(
                    newDefinition,
                    this.scheduler.SelectedTimeSlot);
                this.RecreateTimeSlots();
                this.scheduler.SelectedTimeSlot = selectedTimeSlot;
            }
        }
 /// <summary>
 /// Gets the start date for view definition.
 /// </summary>
 /// <param name="definition">The definition.</param>
 /// <param name="selectedDate">The selected date.</param>
 /// <returns></returns>
 public DateTime GetStartDateForViewDefinition(ViewDefinitionBase definition, DateTime selectedDate)
 {
     if (definition is MonthViewDefinition)
     {
         return(this.scheduler.FirstDayOfFirstWeekOfMonthForVisibleDate(selectedDate));
     }
     if (definition is WeekViewDefinition)
     {
         return(this.scheduler.FirstDayOfWeekForVisibleDate(selectedDate));
     }
     if (definition is TimelineViewDefinition)
     {
         var delta = DateTimeInterval.FromDays((this.scheduler.SelectedTimeSlot.Start - this.visibleRangeStart).Days % definition.VisibleDays);
         if (this.scheduler.SelectedTimeSlot.Start < this.visibleRangeEnd && this.scheduler.SelectedTimeSlot.Start > this.visibleRangeStart)
         {
             return(selectedDate.SubtractInterval(delta));
         }
     }
     return(selectedDate);
 }
Exemple #6
0
 public SingleMonthWeekViewDefinition(ViewDefinitionBase activeViewDefinition)
 {
     this.ActiveViewDefinition = activeViewDefinition;
 }