Data Binding Support Overview
Data binding allows you to establish a link between the UI and the underlying business logic and keep them synchronized. It means that when a value is changed in the business layer, that change is automatically populated to the UI and vice versa. Of course, in order to work, you have to implement the proper notification or to use objects that have already implemented it.
Binding to RadScheduler involves the following properties:
AppointmentsSource
AppointmentsSource: Gets or sets the data source (IEnumerable) used to generate the Appointments in the RadScheduler control. It can be bound to data from a variety of data sources in the form of common language runtime (CLR) objects and XML.
Note that the data source passed to the property AppointmentsSource should contain only objects that implement the IAppointment interface.
Example 1: Defining the AppointmentsSource collection in the view model
public class MyViewModel : ViewModelBase
{
private BindableCollection<Appointment> appointments;
public BindableCollection<Appointment> Appointments
{
get
{
if (this.appointments == null)
{
this.appointments = this.CreateAppointments();
}
return this.appointments;
}
}
private BindableCollection<Appointment> CreateAppointments()
{
var apps = new BindableCollection<Appointment>();
var app1 = new Appointment
{
Subject = "Front-End Meeting",
Start = DateTime.Today.AddHours(9),
End = DateTime.Today.AddHours(10)
};
apps.Add(app1);
var app2 = new Appointment
{
Subject = "Planning Meeting",
Start = DateTime.Today.AddHours(11),
End = DateTime.Today.AddHours(12)
};
apps.Add(app2);
return apps;
}
}
Example 2: Binding the AppointmentsSource
<telerik:RadScheduler x:Name="scheduler"
DataContext="{StaticResource MyViewModel}"
AppointmentsSource="{Binding Appointments}">
<telerik:RadScheduler.ViewDefinitions>
<telerik:WeekViewDefinition/>
<telerik:DayViewDefinition />
</telerik:RadScheduler.ViewDefinitions>
</telerik:RadScheduler>
ResourceTypesSource
ResourceTypesSource: Gets or sets the data source (IEnumerable) used to generate the ResourceTypes of the RadScheduler control. It can be bound to data from a variety of data sources in the form of common language runtime (CLR) objects and XML.
Note that the data source passed to the property ResourceTypesSource should contain only objects of type ResourceType.
Example 3: Defining the ResourceTypesSource collection in the view model
private BindableCollection<ResourceType> resourceTypesSource;
public BindableCollection<ResourceType> ResourceTypesSource
{
get
{
if (this.resourceTypesSource == null)
{
this.resourceTypesSource = new BindableCollection<ResourceType>(this.CreateResources());
}
return this.resourceTypesSource;
}
}
private List<ResourceType> CreateResources()
{
IEnumerable<IResource> resourcesProgrammes;
IEnumerable<IResource> resourcesTVs;
List<ResourceType> resourceTypes;
resourcesProgrammes = new List<IResource>
{
new Resource("Movies", "Programme"),
new Resource("Sports", "Programme"),
new Resource("Shows", "Programme"),
new Resource("Kids", "Programme"),
};
resourcesTVs = new List<IResource>
{
new Resource("LiveCastNews", "TV"),
new Resource("Voozy", "TV"),
new Resource("Sportix", "TV"),
};
resourceTypes = new List<ResourceType>();
ResourceType resourceTypeProgramme = new ResourceType("Programme");
resourceTypeProgramme.Resources.AddRange(resourcesProgrammes);
ResourceType resourceTypeTV = new ResourceType("TV");
resourceTypeTV.Resources.AddRange(resourcesTVs);
resourceTypes.Add(resourceTypeProgramme);
resourceTypes.Add(resourceTypeTV);
return resourceTypes;
}
Example 4: Binding the ResourceTypesSource
<telerik:RadScheduler x:Name="scheduler" DataContext="{StaticResource MyViewModel}" ResourceTypesSource="{Binding ResourceTypesSource}"
AppointmentsSource="{Binding Appointments}">
<telerik:RadScheduler.ViewDefinitions>
<telerik:WeekViewDefinition/>
<telerik:DayViewDefinition />
</telerik:RadScheduler.ViewDefinitions>
</telerik:RadScheduler>
CategoriesSource
CategoriesSource: Gets or sets the data source (IEnumerable) used to generate the Categories in the RadScheduler control. It can be bound to data from a variety of data sources in the form of common language runtime (CLR) objects and XML.
Note that the data source passed to the property CategoriesSource should contain only objects of type Category.
Example 5: Defining the Categories colleciton in the view model
private BindableCollection<Category> categories;
public BindableCollection<Category> Categories
{
get
{
if (this.categories == null)
{
this.categories = this.CreateCategories();
}
return this.categories;
}
}
private BindableCollection<Category> CreateCategories()
{
BindableCollection<Category> categories = new BindableCollection<Category>() {
new Category( "Red Category", new SolidColorBrush( Colors.Red ) ),
new Category( "Orange Category", new SolidColorBrush( Colors.Orange ) ),
new Category( "Green Category", new SolidColorBrush( Colors.Green ) )};
return categories;
}
Example 6: Binding the CategoriesSource
<telerik:RadScheduler x:Name="scheduleView"
DataContext="{StaticResource MyViewModel}"
CategoriesSource="{Binding Categories}"
AppointmentsSource="{Binding Appointments}">
<telerik:RadScheduler.ViewDefinitions>
<telerik:WeekViewDefinition/>
<telerik:DayViewDefinition />
</telerik:RadScheduler.ViewDefinitions>
</telerik:RadScheduler>
TimeMarkersSource
TimeMarkersSource: Gets or sets the data source (IEnumerable) used to generate the TimeMarkers in the RadScheduler control. It can be bound to data from a variety of data sources in the form of common language runtime (CLR) objects and XML.
Note that the data source passed to the property TimeMarkersSource should contain only objects of type TimeMarker.
Example 7: Defining the TimeMarkers colleciton in the view model
private BindableCollection<TimeMarker> timeMarkers;
public BindableCollection<TimeMarker> TimeMarkers
{
get
{
if (this.timeMarkers == null)
{
this.timeMarkers = this.CreateTimeMarkers();
}
return this.timeMarkers;
}
}
private BindableCollection<TimeMarker> CreateTimeMarkers()
{
BindableCollection<TimeMarker> timeMarkers = new BindableCollection<TimeMarker>() {
new TimeMarker("Busy", new SolidColorBrush( Colors.Red ) ),
new TimeMarker("Free", new SolidColorBrush( Colors.Green ) )};
return timeMarkers;
}
Example 8: Binding the TimeMarkersSource
<telerik:RadScheduler x:Name="scheduleView"
DataContext="{StaticResource MyViewModel}"
TimeMarkersSource="{Binding TimeMarkers}"
AppointmentsSource="{Binding Appointments}">
<telerik:RadScheduler.ViewDefinitions>
<telerik:WeekViewDefinition/>
<telerik:DayViewDefinition />
</telerik:RadScheduler.ViewDefinitions>
</telerik:RadScheduler>
GroupDescriptionsSource
GroupDescriptionsSource: Gets or sets the data source (IEnumerable<GroupDescription>) used to generate the GroupDescriptions in the RadScheduler control. It can be bound to data from a variety of data sources in the form of common language runtime (CLR) objects and XML.
Note that the data source passed to the property GroupDescriptionsSource should contain only objects of type GroupDescription.
Example 9: Defining the GroupDescriptions colleciton in the view model
private GroupDescriptionCollection groupDescriptions;
public GroupDescriptionCollection GroupDescriptions
{
get
{
if (this.groupDescriptions == null)
{
this.groupDescriptions = new GroupDescriptionCollection() { new DateGroupDescription() };
TimeZoneGroupDescription groupDescription = new TimeZoneGroupDescription();
this.groupDescriptions.Add(groupDescription);
}
return this.groupDescriptions;
}
}
Example 10: Binding the GroupDescriptionsSource
<telerik:RadScheduler x:Name="scheduleView"
DataContext="{StaticResource MyViewModel}"
GroupDescriptionsSource="{Binding GroupDescriptions}"
AppointmentsSource="{Binding Appointments}">
<telerik:RadScheduler.ViewDefinitions>
<telerik:WeekViewDefinition/>
<telerik:DayViewDefinition />
</telerik:RadScheduler.ViewDefinitions>
</telerik:RadScheduler>