Scheduler Components and Controls > Binding C1Scheduler using WPF > Binding C1Scheduler to a Data Source |
In this topic, we will bind to C1Scheduler the Schedule.mdb database that is installed with Scheduler for WPF by default. First we must configure the datasource. Then we can add the dataset as a resource in the Blend project and map to the C1Scheduler Data Storage.
To configure the data source in Visual Studio 2008:
XAML |
Copy Code
|
---|---|
using C1.WPF.Schedule; using C1.Schedule; using MYProjectNAME.ScheduleDataSetTableAdapters; |
Note that this last using statement should contain the name of your project to work correctly. It will be used to set up the table adapter for your data set.
XAML |
Copy Code
|
---|---|
public partial class Page1 : System.Windows.Controls.Page { private ScheduleDataSet _schedulerDataSet = null; public Page1() { InitializeComponent(); // Use the data set to fill in the data. FillData(SchedulerDataSet); } public ScheduleDataSet SchedulerDataSet { get { if (_schedulerDataSet == null) { _schedulerDataSet = Resources["dataSet"] as ScheduleDataSet; } return _schedulerDataSet; } } private void FillData(ScheduleDataSet ds) { if (ds == null) return; AppointmentsTableAdapter appAd = new AppointmentsTableAdapter(); appAd.Fill(ds.Appointments); } } |
To add the new dataset as a resource to your Blend project:
xmlns:local="clr-namespace:MYProjectNAME"
Your XAML code should look similar to the following:
XAML |
Copy Code
|
---|---|
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="WpfApplication1.Page1" xmlns:local="clr-namespace:WpfApplication1" Title="Page1" xmlns:c1sched="http://schemas.componentone.com/wpf/Schedule"> |
XAML |
Copy Code
|
---|---|
<Page.Resources> <local:ScheduleDataSet x:Key="dataSet" /> </Page.Resources> |
To map to the C1Scheduler Data Storage:
Property |
Text |
Body |
Body |
End |
End |
Location |
Location |
Start |
Start |
Subject |
Subject |
AppointmentProperties |
Properties |
IdMapping |
Id |
IndexMapping |
N/A |
XAML |
Copy Code
|
---|---|
<c1:C1Scheduler Margin="0,0,-80,-80" Theme="{DynamicResource {ComponentResourceKey ResourceId=Office2007.Blue, TypeInTargetAssembly={x:Type c1sched:C1Scheduler}}}"> <c1:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.DataMember" Value="Appointments"/> <c1:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.DataSource" Value="{DynamicResource dataSet}"/> <c1:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.Body.MappingName" Value="Body"/> <c1:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.End.MappingName" Value="End"/> <c1:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.Location.MappingName" Value="Location"/> <c1:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.Start.MappingName" Value="Start"/> <c1:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.Subject.MappingName" Value="Subject"/> <c1:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.AppointmentProperties.MappingName" Value="Properties"/> <c1:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.IdMapping.MappingName" Value="Id"/> <c1:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.IndexMapping.MappingName" Value="N/A"/> <c1:C1Scheduler> |