Intersoft ClientUI 8 > ClientUI Controls > Control Library > Scheduling Controls Overview > UXScheduleView > UXScheduleView Walkthroughs > Walkthrough: Bind UXScheduleView to WCF RIA Services using MVVM Pattern |
This walkthrough provides step-by-step instructions to bind UXScheduleView to WCF RIA Services and displaying a collection of data using MVVM pattern.
In this walkthrough, you will perform the following tasks:
You need the following components to complete this walkthrough:
The first step is to create a new ClientUI MVVM Schedule Application (WCF RIA SP1) project using Intersoft ClientUI MVVM Schedule Application (WCF RIA SP1) project template in Visual Studio.
This section shows how to create the SoftwareDevEventsRepository class, SoftwareDevCategoriesRepository class and SoftwareDevResourcesRepository class that represents the required data repositories used in this walkthrough.
This section steps you through the process of adding a new calendar page to display a collection of software dev data.
C# |
Copy Code
|
---|---|
<Grid x:Name="LayoutRoot"> <Intersoft:UXScheduleView x:Name="SampleControl1" DisplayDate="1/2/2012" NavigationPanePlaceHolderId="CalendarDevContainer" NavigationPaneBackground="{x:Null}" CalendarHeaderBackground="{x:Null}"> <Intersoft:UXScheduleDayView /> <Intersoft:UXScheduleWorkWeekView /> <Intersoft:UXScheduleWeekView IsActive="True"/> <Intersoft:UXScheduleMonthView /> </Intersoft:UXScheduleView> </Grid> |
This section steps you through the process of creating a ViewModel class that contains the properties to describe the View that you created in the previous section. The ViewModel will inherit the ScheduleViewModelBase class which already contains a set of common properties that will be used in UXScheduleView such as Events. You can also choose to inherit from EditableScheduleViewModelGenericBase to create a ViewModel that supports data editing features such as add, edit and delete.
C# |
Copy Code
|
---|---|
public class SoftwareDevCalendarViewModel : ScheduleViewModelBase<SoftwareDevEvent> |
C# |
Copy Code
|
---|---|
protected override IDataRepository CategoriesDataSource { get { return SoftwareDevCategoriesRepository.Instance; } } protected override IDataRepository EventsDataSource { get { return SoftwareDevEventsRepository.Instance; } } protected override IDataRepository ResourcesDataSource { get { return SoftwareDevResourcesRepository.Instance; } } |
In the previous sections, you have learned how to create the Model and ViewModel classes, as well as the View that contains the user interface and controls used in this walkthrough. This section shows how to instantiate the ViewModel in the XAML page and bind the UI elements to the properties in the ViewModel such as the data context and UXScheduleView EventsSource property.
XAML |
Copy Code
|
---|---|
<Intersoft:UXPage... xmlns:ViewModels="clr-namespace:ClientUI_Schedule_Application.ViewModels" </Intersoft:UXPage> |
XAML |
Copy Code
|
---|---|
<Intersoft:UXPage.Resources> <ViewModels:CalendarDevViewModel x:Key="CalendarDevViewModel" /> ... </Intersoft:UXPage.Resources> <Grid x:Name="LayoutRoot" DataContext="{StaticResource CalendarDevViewModel}"> </Grid> |
XAML |
Copy Code
|
---|---|
<Intersoft:UXScheduleView x:Name="SampleControl1" DisplayDate="1/2/2012" NavigationPanePlaceHolderId="CalendarDevContainer" NavigationPaneBackground="{x:Null}" CalendarHeaderBackground="{x:Null}" IsBusy="{Binding IsBusy,Mode=TwoWay}" EventsSource="{Binding Events}" CategoriesSource="{Binding Categories}" ResourcesSource="{Binding Resources}"> <Intersoft:UXScheduleDayView /> <Intersoft:UXScheduleWorkWeekView /> <Intersoft:UXScheduleWeekView IsActive="True"/> <Intersoft:UXScheduleMonthView /> </Intersoft:UXScheduleView> |
XAML |
Copy Code
|
---|---|
<Intersoft:UXNavigationPaneItem Header="Calendar" NavigateUri="/Calendar/All" NavigationState="/Calendar" Icon="Assets/Images/Calendar.png"> <Grid x:Name="ExternalContainer"/> </Intersoft:UXNavigationPaneItem> <Intersoft:UXNavigationPaneItem Header="CalendarDev" NavigateUri="/CalendarDev" NavigationState="/CalendarDev" Icon="Assets/Images/Calendar.png"> <Grid x:Name="CalendarDevContainer"/> </Intersoft:UXNavigationPaneItem> |
In this walkthrough, you have learned how to create ClientUI MVVM Schedule Application (WCF RIA SP1) using project template, and create the classes and page based on the Model, View and ViewModel pattern. You also learned how to bind UXScheduleView to a collection of data.
This section lists the complete code used in this walkthrough.
C# |
Copy Code
|
---|---|
using System.ServiceModel.DomainServices.Client; using ClientUI_Schedule_Application.Web; namespace ClientUI_Schedule_Application.ModelServices { public class SoftwareDevCategoriesRepository : DataRepository<SoftwareDevCategory> { private static IDataRepository _repository; /// <summary> /// Initializes a new instance of <see cref="PublicationCategoriesRepository"/> class. /// </summary> /// <param name="context">A <see cref="DomainContext"/> instance, providing access to all functionality of the data service.</param> public SoftwareDevCategoriesRepository(DomainContext context) : base(context) { } private static bool IsReusable { get { return true; } } private ScheduleViewSampleDataDomainContext EntityContext { get { return ((ScheduleViewSampleDataDomainContext)this.Context); } } /// <summary> /// Returns an instance of <see cref="PublicationCategoriesRepository"/>. /// If the <see cref="IsReusable"/> is true, the property will return an existing cached copy of the instance. /// </summary> public static IDataRepository Instance { get { if (_repository == null || !IsReusable) _repository = new SoftwareDevCategoriesRepository(RepositoryManager.Create()); return _repository; } } /// <summary> /// Gets the <see cref="EntitySet"/> that provides access to a collection of entities as the results of the entity query. /// </summary> public override EntitySet<SoftwareDevCategory> EntitySet { get { return this.EntityContext.SoftwareDevCategories; } } /// <summary> /// Gets the <see cref="EntityQuery"/> that represents the entity's LINQ query. /// </summary> public override EntityQuery<SoftwareDevCategory> EntityQuery { get { return this.EntityContext.GetSoftwareDevCategoriesQuery(); } } } } |
C# |
Copy Code
|
---|---|
using System.ServiceModel.DomainServices.Client; using ClientUI_Schedule_Application.Web; namespace ClientUI_Schedule_Application.ModelServices { public class SoftwareDevEventsRepository : EditableDataRepository<SoftwareDevEvent> { private static IDataRepository _repository; /// <summary> /// Initializes a new instance of <see cref="PublicationCategoriesRepository"/> class. /// </summary> /// <param name="context">A <see cref="DomainContext"/> instance, providing access to all functionality of the data service.</param> public SoftwareDevEventsRepository(DomainContext context) : base(context) { } private static bool IsReusable { get { return true; } } private ScheduleViewSampleDataDomainContext EntityContext { get { return ((ScheduleViewSampleDataDomainContext)this.Context); } } /// <summary> /// Returns an instance of <see cref="PublicationCategoriesRepository"/>. /// If the <see cref="IsReusable"/> is true, the property will return an existing cached copy of the instance. /// </summary> public static IDataRepository Instance { get { if (_repository == null || !IsReusable) _repository = new SoftwareDevEventsRepository(RepositoryManager.Create()); return _repository; } } /// <summary> /// Gets the <see cref="EntitySet"/> that provides access to a collection of entities as the results of the entity query. /// </summary> public override EntitySet<SoftwareDevEvent> EntitySet { get { return this.EntityContext.SoftwareDevEvents; } } /// <summary> /// Gets the <see cref="EntityQuery"/> that represents the entity's LINQ query. /// </summary> public override EntityQuery<SoftwareDevEvent> EntityQuery { get { return this.EntityContext.GetSoftwareDevEventsQuery(); } } } } |
C# |
Copy Code
|
---|---|
using System.ServiceModel.DomainServices.Client; using ClientUI_Schedule_Application.Web; namespace ClientUI_Schedule_Application.ModelServices { public class SoftwareDevResourcesRepository : DataRepository<SoftwareDevResource> { private static IDataRepository _repository; /// <summary> /// Initializes a new instance of <see cref="PublicationCategoriesRepository"/> class. /// </summary> /// <param name="context">A <see cref="DomainContext"/> instance, providing access to all functionality of the data service.</param> public SoftwareDevResourcesRepository(DomainContext context) : base(context) { } private static bool IsReusable { get { return true; } } private ScheduleViewSampleDataDomainContext EntityContext { get { return ((ScheduleViewSampleDataDomainContext)this.Context); } } /// <summary> /// Returns an instance of <see cref="PublicationCategoriesRepository"/>. /// If the <see cref="IsReusable"/> is true, the property will return an existing cached copy of the instance. /// </summary> public static IDataRepository Instance { get { if (_repository == null || !IsReusable) _repository = new SoftwareDevResourcesRepository(RepositoryManager.Create()); return _repository; } } /// <summary> /// Gets the <see cref="EntitySet"/> that provides access to a collection of entities as the results of the entity query. /// </summary> public override EntitySet<SoftwareDevResource> EntitySet { get { return this.EntityContext.SoftwareDevResources; } } /// <summary> /// Gets the <see cref="EntityQuery"/> that represents the entity's LINQ query. /// </summary> public override EntityQuery<SoftwareDevResource> EntityQuery { get { return this.EntityContext.GetSoftwareDevResourcesQuery(); } } } } |
C# |
Copy Code
|
---|---|
using ClientUI_Schedule_Application.ModelServices; using ClientUI_Schedule_Application.Web; namespace ClientUI_Schedule_Application.ViewModels { public class SoftwareDevCalendarViewModel : ScheduleViewModelBase<SoftwareDevEvent> { protected override IDataRepository CategoriesDataSource { get { return SoftwareDevCategoriesRepository.Instance; } } protected override IDataRepository EventsDataSource { get { return SoftwareDevEventsRepository.Instance; } } protected override IDataRepository ResourcesDataSource { get { return SoftwareDevResourcesRepository.Instance; } } } } |
XAML |
Copy Code
|
---|---|
<Intersoft:UXPage xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:Intersoft="http://intersoft.clientui.com/schemas" xmlns:ViewModels="clr-namespace:ClientUI_Schedule_Application.ViewModels" x:Class="ClientUI_Schedule_Application.Views.CalendarDev" Title="CalendarDev Page" d:DesignWidth="640" d:DesignHeight="480"> <Intersoft:UXPage.Resources> <ViewModels:SoftwareDevCalendarViewModel x:Key="SoftwareDevCalendarViewModel"/> </Intersoft:UXPage.Resources> <Grid x:Name="LayoutRoot" DataContext="{StaticResource SoftwareDevCalendarViewModel}"> <Intersoft:UXScheduleView x:Name="SampleControl1" DisplayDate="1/2/2012" NavigationPanePlaceHolderId="CalendarDevContainer" NavigationPaneBackground="{x:Null}" CalendarHeaderBackground="{x:Null}" IsBusy="{Binding IsBusy,Mode=TwoWay}" EventsSource="{Binding Events}" CategoriesSource="{Binding Categories}" ResourcesSource="{Binding Resources}"> <Intersoft:UXScheduleDayView /> <Intersoft:UXScheduleWorkWeekView /> <Intersoft:UXScheduleWeekView IsActive="True"/> <Intersoft:UXScheduleMonthView /> </Intersoft:UXScheduleView> </Grid> </Intersoft:UXPage> |