New to Telerik UI for WPF? Download free 30-day trial

View and ViewModel

This article will demonstrate how to implement the View and the ViewModel.

Presentation tier (xaml)

When the models are defined, we need to create the ViewModel (refer to ScheduleViewViewModel class) and bind the ScheduleView control in the xaml:

<Grid x:Name="LayoutRoot" Background="White"> 
        <RowDefinition Height="*"/> 
        <RowDefinition Height="Auto"/> 
    <telerik:RadBusyIndicator IsBusy="{Binding IsLoading}"> 
        <telerik:RadScheduleView Grid.Row="0"     
            AppointmentsSource="{Binding Appointments}" 
            ResourceTypesSource="{Binding ResourceTypes}" 
            TimeMarkersSource="{Binding TimeMarkers}" 
            CategoriesSource="{Binding Categories}" 
            VisibleRangeChangedCommand="{Binding VisibleRangeChanged}" 
            VisibleRangeChangedCommandParameter="{Binding VisibleRange, RelativeSource={RelativeSource Self}}"> 
                <telerik:WeekViewDefinition /> 
                <telerik:MonthViewDefinition  /> 
                <telerik:TimelineViewDefinition /> 
                    <telerik:DateGroupDescription /> 
                    <telerik:ResourceGroupDescription ResourceType="Level" ShowNullGroup="True" /> 
                    <telerik:ResourceGroupDescription ResourceType="Speaker" ShowNullGroup="True" /> 
    <Button Grid.Row="1" Content="Save data" HorizontalAlignment="Center" Command="{Binding SaveCommand}" VerticalAlignment="Center"/> 

The appointments are loaded from the database when the VisibleRangeChanged command is executed.

When "Save data" button is clicked, we save the data to the server.

private void OnSaveExecuted(object param)  
public static bool SaveData() 
    return ScheduleViewRepository.Context.SaveChanges() > 0; 


In the constructor we load the data for the ScheduleView control (without appointments, they are loaded later). First, we need to load the SqlResource and SqlResourceTypes. When both are loaded, we can added the resources to the ResourceTypes collection.

Load the SqlTimeMarkers and the SqlCategories and add them to the TimeMarkers and Categories collections.

Here is the code:

private void LoadData() 
Also, we need to handle the Appointments.CollectionChanged event and in the handler we add or remove the items from the ObjectSets:

private void OnAppointmentsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) 
    if (e.Action == NotifyCollectionChangedAction.Add) 
        var app = e.NewItems == null ? null : e.NewItems[0] as SqlAppointment; 
        if (app != null && app.EntityState == EntityState.Added) 
    else if (e.Action == NotifyCollectionChangedAction.Remove) 
        var app = e.OldItems == null ? null : e.OldItems[0] as SqlAppointment; 
        if (app != null && ScheduleViewRepository.Context.SqlAppointments.Any(a => a.SqlAppointmentId == app.SqlAppointmentId)) 
            if (app.RecurrenceRule != null) 
                var tempList = app.RecurrenceRule.Exceptions.ToList(); 
                foreach (SqlExceptionOccurrence item in tempList) 
            var tempAppList = ScheduleViewRepository.Context.SqlAppointmentResources.ToList(); 
            foreach (var item in tempAppList) 
In this article
Not finding the help you need? Improve this article