You need the following components to complete this walkthrough:
- Visual Studio 2010
- Silverlight 4 Tools for Visual Studio 2010
- Intersoft ClientUI
In addition, you also need the following resources to complete this walkthrough:
- Intersoft.ClientUI.Samples.Assets assembly
Available in: [Intersoft Installation Folder]\Intersoft WebUI Studio 2010 R1\Samples\SL4\ClientUI Samples\Intersoft.ClientUI.Samples.Assets\Bin\Debug
Creating an Intersoft ClientUI MVVM Application Project
The first step is to create a new ClientUI MVVM Application project using Intersoft ClientUI MVVM Application project template in Visual Studio.
To create the ClientUI MVVM Application project
- Start Visual Studio 2010.
- Create a new ClientUI MVVM Application project using Intersoft ClientUI MVVM Application project template. To learn more, see Walkthrough: Create New Intersoft ClientUI MVVM Application Template.
- In project reference, add System.Xml.Linq.dll. This assembly is required to perform LINQ query to xml data.
- Also add reference to Intersoft.ClientUI.Samples.Assets assembly, the assembly is available from the provided ClientUI sample.
Creating Model Class
This section shows how to create a Model class in Book.cs. The model will map each information in the data entity to a property.
To create the Book model class
- Create a new Book.cs under the Models folder and inherit the ModelBase class.
Create a private variable and a public property for Author node with a String data type. In the setter property, OnPropertyChanged method must be called after the property is assigned a new value.
- Repeat the process for ID, Title, Category, Price, and Image node. String data type is used for ID, Title, and Category. Double is used for Price. Uri is used for Image.
Create a constructor which accept XElement parameter. The constructor maps information in the data entity to each property in the class.
Creating the ViewModel Class
This section shows how to create a ViewModel to hold the collection of Book model object.
To create the BookFlowViewModel ViewModel class
- Create a new BookFlowViewModel.cs under the ViewModels folder and inherit the ViewModelBase class.
Create a public property to hold the collection of Book model object.
Create a LoadBooks method which will be called in the constructor to load the Book object from the XML file to the book collection variable. In this scenario, only books with specific category is loaded.
Creating the View
This section shows how to create the View used in the application interface using the BookFlow.xaml. Binding data to the control and setting the overflow panel using UXOverflowStackPanel also done in this section.
To create the BookFlow view
Add a new UXPage to the Views folder in your Silverlight project and name it BookFlow.xaml.For more information on how to add a new item in Visual Studio, see Walkthrough: Add New Item such as Page, Dialog Box and Window in VS 2010
Declare the namespace that maps to the BookFlowViewModel class.
Reference the BookFlowViewModel as the page DataContext.
Add a new UXWindow with a predefined size to ensure item will be overflow. Set the following properties:
- Bind the BookFlowViewModel to the UXItemsControl and use Horizontal as the UXItemsControl Orientation.
Modify the UXItemsControl ItemTemplate, use Image control and bind the Source property to Image property in the ViewModel.
To create the overflow panel
- Set Background to Gray in order to differentiate between the panel and overflow panel.
- Modify the StackPanelOrientation to Vertical.
Viewing the Result
In order to view the result, you will need to build the Silverlight project and run the test page in browser.
To test the result
- Resizing the UXWindow will move the overflow item to the StackPanel.
In this walkthrough, you have learned how to create ClientUI MVVM Application project using Intersoft ClientUI MVVM Application project template, and create classes and page based on the MVVM pattern. You also learned how to bind UXItemsControl to a collection of data and how to use UXOverflowStackPanel to hold the overflow item.
For more information about application development using MVVM pattern, see MVVM Pattern Overview.
Complete Code Listing
This section lists the complete code used in this walkthrough.