ComponentOne Scheduler for WPF and Silverlight
Scheduler Components and Controls / Binding C1Scheduler using Silverlight / Binding AppointmentStorage to a Collection of Custom Business Objects
In This Topic
    Binding AppointmentStorage to a Collection of Custom Business Objects
    In This Topic
    1. Create a new Silverlight application and add an instance of C1Scheduler to the Page.
    2. Add a new code file to your application and define a custom business object class. Note that the following definition only shows a public interface of this class; the full definition can be found in the C1Scheduler_BusinessObjectsBinding sample included with this product):

      C#
      Copy Code
      // Business object should implement INotifyPropertyChanged interface.
      public class AppointmentBORow : INotifyPropertyChanged
      {
          public AppointmentBORow();
          public string Subject { get; set; }
          public DateTime Start { get; set; }
          public DateTime End { get; set; }
          public string Body { get; set; }
          public string Location { get; set; }
          public string Properties { get; set; }
          public Guid Id { get; set; }
          public bool IsDeleted { get; set; }
          public event PropertyChangedEventHandler PropertyChanged;
      }
      

       

    3. Add a class that will hold collection of AppointmentBORow objects:

      C#
      Copy Code
      // Business objects collection should implement
      // INotifyCollectionChanged interface.
      public class AppointmentBOList : ObservableCollection<AppointmentBORow>
      {
      }
      

    4. Add a custom data source class:

      C#
      Copy Code
      public class AppointmentsBO
      {
          AppointmentBOList _list = new AppointmentBOList();
        
          public AppointmentsBO(){ }
      
          public AppointmentBOList Appointments
          {
              get
              {
                  return _list;
              }
              set
              {
                  _list = value;
              }
          }
      }
      

    5. Create an instance of the AppointmentsBO class on a Page containing the C1Scheduler object:

      XAML
      Copy Code
      <UserControl
          xmlns:c1sched="clr-namespace:C1.Silverlight.Schedule;assembly=C1.Silverlight.Schedule"
          x:Class="C1Scheduler_BusinessObjectsBinding.MainPage"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:c1="clr-namespace:C1.Silverlight;assembly=C1.Silverlight"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:local="clr-namespace:C1Scheduler_BusinessObjectsBinding"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Loaded="UserControl_Loaded"
          mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480" FontFamily="Segoe UI">
          <UserControl.Resources>
              <!-- Create instance of custom class keeping collection of business objects. -->
              <local:AppointmentsBO x:Key="_ds" />
      </UserControl.Resources>
      

    6. Use NestedPropertySetters to set mappings between the properties of AppointmentBORow objects and AppointmentStorage and to set the AppointmentStorage.DataSource property:

      XAML
      Copy Code
      <c1sched:C1Scheduler x:Name="sched1" >
          <!-- Map AppointmentStorage to collection of business objects -->
          <c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.AppointmentProperties.MappingName" Value="Properties"/>
          <c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.Body.MappingName"
       Value="Body"/>
          <c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.End.MappingName"
       Value="End"/>
          <c1sched: PropertyName="DataStorage.AppointmentStorage.Mappings.IdMapping.MappingName" Value="Id"/>
          <c1sched: PropertyName="DataStorage.AppointmentStorage.Mappings.Location.MappingName" Value="Location"/>
          <c1sched: PropertyName="DataStorage.AppointmentStorage.Mappings.Start.MappingName" Value="Start"/>
          <c1sched: PropertyName="DataStorage.AppointmentStorage.Mappings.Subject.MappingName" Value="Subject"/>
          <c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.DataSource"
       Value="{Binding Path=Appointments, Mode=TwoWay, Source={StaticResource _ds}}" />
      </c1sched:C1Scheduler>
      

    That’s all you need to do. At run time, any change to the AppointmentBOList will be reflected in C1Scheduler and vice versa.