Version

Using Custom Entity Types (XamScheduler)

Purpose

This topic explains how to bind the control to a data source which uses custom entity types.

Required Background

Topic Purpose

This topic provides an overview of the XamScheduler control.

This topic explains how to bind the control to a data source using ScheduleListDataSource.

Overview

If you have a collection of custom entity objects and you want to use it for either activities or resources you may use the ScheduleListDataSource's mapping infrastructure described below which will help the XamScheduler in recognizing the custom object’s fields. The ScheduleListDataSource class has two key properties for creating such mappings:

Create Mapping for Custom Activity Objects

The following steps are showing how to create mappings for you custom activity entity objects:

  1. Create a ScheduleListDataSource instance

  2. Set its AppointmentItemsSource property to your activity entity objects collection

  3. Add mappings in the AppointmentPropertyMappings collection for each property you need to map between your custom activity objects and the XamScheduler's activities.

  4. The mappings are of type AppointmentPropertyMapping and have the following key properties which you should set:

    1. Property of type AppointmentProperty used to specify the XamScheduler activity’s field

    2. DataObjectPropertyName of type string used to specify the property name in your custom activity entity object

  5. Set the ScheduleListDataSource instance created in step 1 to the DataSource property of the XamScheduler.

Note
Note

The mandatory fields you need to set for each activity are: Start, End and Id.

Create Mapping for Custom Resource Objects

The following steps are showing how to create mappings for your custom resource entity objects:

  1. Create a ScheduleListDataSource instance

  2. Set its ResourceItemsSource property to your resource entity objects collection

  3. Add mappings in the ResourcePropertyMappings collection for each property you need to map between your custom resource objects and the XamScheduler's resources.

  4. The mappings are of type ResourcePropertyMapping and have the following key properties which you should set:

    1. Property of type ScheduleResourceProperty used to specify the XamScheduler resource’s field

    2. DataObjectPropertyName of type string used to specify the property name in your custom resource entity object

  5. Set the ScheduleListDataSource instance created in step 1 to the DataSource property of the XamScheduler.

Note
Note

The mandatory fields you need to set for each resource are: Id and DisplayName.

Code Example

The following code example demonstrates how to define custom mappings for both appointments and resources. The code snippet assumes you are having a view model named "CustomViewModel" with properties "Duties" and "Owners", containing all custom objects for appointments (of type Duty) and resources (of type Owner) respectively.

In XAML:

<ig:XamScheduler>

    <ig:XamScheduler.BindingContext>
        <local:CustomViewModel />
    </ig:XamScheduler.BindingContext>

    <ig:XamScheduler.DataSource>
        <ig:ScheduleListDataSource
            AppointmentItemsSource="{Binding Duties}"
            ResourceItemsSource="{Binding Owners}">

        <ig:ScheduleListDataSource.AppointmentPropertyMappings>
            <ig:AppointmentPropertyMappingsCollection>
                <ig:AppointmentPropertyMapping Property="Start" DataObjectPropertyName="DutyStartTime" />
                <ig:AppointmentPropertyMapping Property="End" DataObjectPropertyName="DutyEndTime" />
                <ig:AppointmentPropertyMapping Property="Subject" DataObjectPropertyName="DutyShortName" />
                <ig:AppointmentPropertyMapping Property="Description" DataObjectPropertyName="DutyLongName" />
                <ig:AppointmentPropertyMapping Property="Location" DataObjectPropertyName="DutyPlace" />
                <ig:AppointmentPropertyMapping Property="ResourceId" DataObjectPropertyName="OwnerId"/>
                <ig:AppointmentPropertyMapping Property="Id" DataObjectPropertyName="DutyId"/>
            </ig:AppointmentPropertyMappingsCollection>
        </ig:ScheduleListDataSource.AppointmentPropertyMappings>

        <ig:ScheduleListDataSource.ResourcePropertyMappings>
            <ig:ResourcePropertyMappingsCollection>
                <ig:ResourcePropertyMapping Property="DisplayName" DataObjectPropertyName="OwnerName" />
                <ig:ResourcePropertyMapping Property="ColorScheme" DataObjectPropertyName="OwnerSpecificColor" />
                <ig:ResourcePropertyMapping Property="Id" DataObjectPropertyName="OwnerId" />
            </ig:ResourcePropertyMappingsCollection>
        </ig:ScheduleListDataSource.ResourcePropertyMappings>

    </ig:XamScheduler.DataSource>
</ig:XamScheduler>

In C#:

ScheduleListDataSource slds = new ScheduleListDataSource();
slds.AppointmentItemsSource = Duties;
slds.ResourceItemsSource = Owners;

slds.AppointmentPropertyMappings.Add(
    new AppointmentPropertyMapping()
    {
        Property = AppointmentProperty.Start,
        DataObjectPropertyName = nameof(Duty.DutyStartTime)
    });

slds.AppointmentPropertyMappings.Add(
    new AppointmentPropertyMapping()
    {
        Property = AppointmentProperty.End,
        DataObjectPropertyName = nameof(Duty.DutyEndTime)
    });

slds.AppointmentPropertyMappings.Add(
    new AppointmentPropertyMapping()
    {
        Property = AppointmentProperty.Subject,
        DataObjectPropertyName = nameof(Duty.DutyShortName)
    });

slds.AppointmentPropertyMappings.Add(
    new AppointmentPropertyMapping()
    {
        Property = AppointmentProperty.Description,
        DataObjectPropertyName = nameof(Duty.DutyLongName)
    });

slds.AppointmentPropertyMappings.Add(
    new AppointmentPropertyMapping()
    {
        Property = AppointmentProperty.Location,
        DataObjectPropertyName = nameof(Duty.DutyPlace)
    });

slds.AppointmentPropertyMappings.Add(
    new AppointmentPropertyMapping()
    {
        Property = AppointmentProperty.Id,
        DataObjectPropertyName = nameof(Duty.DutyId)
    });

slds.AppointmentPropertyMappings.Add(
    new AppointmentPropertyMapping()
    {
        Property = AppointmentProperty.ResourceId,
        DataObjectPropertyName = nameof(Duty.OwnerId)
    });

slds.ResourcePropertyMappings.Add(
    new ResourcePropertyMapping()
    {
        Property = ScheduleResourceProperty.DisplayName,
        DataObjectPropertyName = nameof(Owner.OwnerName)
    });

slds.ResourcePropertyMappings.Add(
    new ResourcePropertyMapping()
    {
        Property = ScheduleResourceProperty.ColorScheme,
        DataObjectPropertyName = nameof(Owner.OwnerSpecificColor)
    });

slds.ResourcePropertyMappings.Add(
    new ResourcePropertyMapping()
    {
        Property = ScheduleResourceProperty.Id,
        DataObjectPropertyName = nameof(Owner.OwnerId)
    });

Related Topics

Topic Purpose

This topic explains the Appointment activity type.

This topic provides information about the resources concept of the XamScheduler control.