SyncfusionExamples/load-on-demand from customers-appointments-wpf-scheduler: This example demonstrates to load appointment on demand in wpf scheduler

About the sample

This examples demonstrates to load appointment on demand from customers in wpf scheduler on two ways.

  • LoadOnDemandEvent(QueryAppointments)
  • LoadOnDemandCommand

LoadOnDemandEvent(QueryAppointments)

Outline a Conduct class for sheduler that implements QueryAppointments function for on-need loading.

community class LoadOnDemandBehavior : Actions

SfScheduler scheduler
shielded override void OnAttached()

this.scheduler = this.AssociatedObject
this.scheduler.QueryAppointments += OnSchedulerQueryAppointments

    personal async void OnSchedulerQueryAppointments(object sender, QueryAppointmentsEventArgs e)
    
        this.scheduler.ShowBusyIndicator = accurate
        await Task.Hold off(1000)
        await this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Motion(() =>
        
            this.scheduler.ItemsSource = this.GenerateSchedulerAppointments(e.VisibleDateRange)
        ))
        this.scheduler.ShowBusyIndicator = false
    


    /// 
    /// System to generate scheduler appointments centered on recent seen date variety.
    /// 
    /// Present-day visible day vary.
    non-public IEnumerable GenerateSchedulerAppointments(DateRange dateRange)
    
        var brush = new ObservableCollection()
        brush.Increase(new SolidColorBrush(Colour.FromArgb(0xFF, 0xA2, 0xC1, 0x39)))
        brush.Incorporate(new SolidColorBrush(Colour.FromArgb(0xFF, 0xD8, 0x00, 0x73)))
        brush.Add(new SolidColorBrush(Color.FromArgb(0xFF, 0x1B, 0xA1, 0xE2)))
        brush.Add(new SolidColorBrush(Shade.FromArgb(0xFF, 0xE6, 0x71, 0xB8)))
        brush.Insert(new SolidColorBrush(Coloration.FromArgb(0xFF, 0xF0, 0x96, 0x09)))
        brush.Add(new SolidColorBrush(Color.FromArgb(0xFF, 0x33, 0x99, 0x33)))
        brush.Add(new SolidColorBrush(Coloration.FromArgb(0xFF, 0x00, 0xAB, 0xA9)))
        brush.Increase(new SolidColorBrush(Color.FromArgb(0xFF, 0xE6, 0x71, 0xB8)))

        var subjectCollection = new ObservableCollection()
        subjectCollection.Increase("Business Assembly")
        subjectCollection.Include("Conference")
        subjectCollection.Include("Healthcare check up")
        subjectCollection.Add("Performance Verify")
        subjectCollection.Insert("Consulting")
        subjectCollection.Include("Project Position Discussion")
        subjectCollection.Increase("Client Meeting")
        subjectCollection.Insert("General Conference")
        subjectCollection.Increase("Yoga Treatment")
        subjectCollection.Add("GoToMeeting")
        subjectCollection.Increase("Approach Execution")
        subjectCollection.Insert("Task Program")

        Random ran = new Random()
        int daysCount = (dateRange.ActualEndDate - dateRange.ActualStartDate).Days
        var appointments = new ObservableCollection()
        for (int i =  i < 50 i++)
        
            var startTime = dateRange.ActualStartDate.AddDays(ran.Next(0, daysCount + 1)).AddHours(ran.Next(0, 24))
            appointments.Add(new SchedulerModel
            
                From = startTime,
                To = startTime.AddHours(1),
                EventName = subjectCollection[ran.Next(0, subjectCollection.Count)],
                Color = brush[ran.Next(0, brush.Count)],
            )
        

        return appointments
    

    protected override void OnDetaching()
    
        this.scheduler.QueryAppointments -= OnSchedulerQueryAppointments
        this.scheduler = null
    

And called the LoadOnDemandBehavior class to scheduler control.


    
        
            
        
    


    
        
            
        
        
            
        
    
          
        
    

LoadOnDemandCommand

Define a ViewModel course that implements Command and manage it by CanExecute and Execute approaches to check out and execute on-demand from customers loading.

general public class LoadOnDemandViewModel : NotificationObject

    /// 
    /// Gets or Sets event collection.
    /// 
    personal IEnumerable events

    /// 
    /// Gets or sets a value indicating whether to display the busy indicator.
    /// 
    non-public bool showBusyIndicator

    /// 
    /// Receives or sets load on demand from customers command.
    /// 
    public ICommand LoadOnDemandCommand  get established 

    /// 
    /// Receives or sets event collection.
    /// 
    general public IEnumerable Functions
    
        get  return events 
        set
        
            events = value
            this.RaisePropertyChanged("Events")
        
    

    /// 
    /// Will get or sets a worth indicating whether or not to present the chaotic indicator.
    /// 
    community bool ShowBusyIndicator
    
        get  return showBusyIndicator 
        set
        
            showBusyIndicator = worth
            this.RaisePropertyChanged("ShowBusyIndicator")
        
    

    /// 
    /// Initializes a new instance of the  course.
    /// 
    public LoadOnDemandViewModel()
    
        if (!DesignerProperties.GetIsInDesignMode(new DependencyObject()))
        
            this.LoadOnDemandCommand = new DelegateCommand(ExecuteOnDemandLoading, CanExecuteOnDemandLoading)
        
    

    /// 
    /// Strategy to excute load on need command and set scheduler appointments.
    /// 
    /// QueryAppointmentsEventArgs item.
    general public async void ExecuteOnDemandLoading(item parameter)
    
        if (parameter == null)
        
            return
        

        this.ShowBusyIndicator = true
        await Endeavor.Hold off(500)
        await Application.Current.MainWindow.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() =>
        
            this.Occasions = this.GenerateSchedulerAppointments((parameter as QueryAppointmentsEventArgs).VisibleDateRange)
        ))
        this.ShowBusyIndicator = fake
    

    /// 
    /// Process to test no matter whether the load on desire command can be invoked or not.
    /// 
    /// QueryAppointmentsEventArgs item.
    personal bool CanExecuteOnDemandLoading(item sender)
    
        return accurate
    

    /// 
    /// Strategy to make scheduler appointments based on present noticeable day range.
    /// 
    /// Current visible date range.
    non-public IEnumerable GenerateSchedulerAppointments(DateRange dateRange)
    
        var brush = new ObservableCollection()
        brush.Add(new SolidColorBrush(Shade.FromArgb(0xFF, 0xA2, 0xC1, 0x39)))
        brush.Add(new SolidColorBrush(Color.FromArgb(0xFF, 0xD8, 0x00, 0x73)))
        brush.Insert(new SolidColorBrush(Color.FromArgb(0xFF, 0x1B, 0xA1, 0xE2)))
        brush.Insert(new SolidColorBrush(Colour.FromArgb(0xFF, 0xE6, 0x71, 0xB8)))
        brush.Add(new SolidColorBrush(Color.FromArgb(0xFF, 0xF0, 0x96, 0x09)))
        brush.Insert(new SolidColorBrush(Coloration.FromArgb(0xFF, 0x33, 0x99, 0x33)))
        brush.Incorporate(new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xAB, 0xA9)))
        brush.Insert(new SolidColorBrush(Color.FromArgb(0xFF, 0xE6, 0x71, 0xB8)))

        var subjectCollection = new ObservableCollection()
        subjectCollection.Increase("Small business Assembly")
        subjectCollection.Increase("Conference")
        subjectCollection.Add("Healthcare examine up")
        subjectCollection.Incorporate("General performance Examine")
        subjectCollection.Insert("Consulting")
        subjectCollection.Insert("Challenge Standing Dialogue")
        subjectCollection.Incorporate("Customer Meeting")
        subjectCollection.Incorporate("Normal Assembly")
        subjectCollection.Add("Yoga Remedy")
        subjectCollection.Insert("GoToMeeting")
        subjectCollection.Incorporate("Approach Execution")
        subjectCollection.Include("Venture Strategy")

        Random ran = new Random()
        int daysCount = (dateRange.ActualEndDate - dateRange.ActualStartDate).Times
        var appointments = new ObservableCollection()
        for (int i =  i < 50 i++)
        
            var startTime = dateRange.ActualStartDate.AddDays(ran.Next(0, daysCount + 1)).AddHours(ran.Next(0, 24))
            appointments.Add(new SchedulerModel
            
                From = startTime,
                To = startTime.AddHours(1),
                EventName = subjectCollection[ran.Next(0, subjectCollection.Count)],
                Color = brush[ran.Next(0, brush.Count)],
            )
        

        return appointments
    

And set the ICommand to LoadOnDemandCommand property of scheduler.