DevExpress MVVM Framework. Using Scaffolding Wizards for building Views.

WPF Team Blog
24 December 2013

OTHER RELATED ARTICLES:

  1. Getting Started with DevExpress MVVM Framework. Commands and View Models.
  2. DevExpress MVVM Framework. Introduction to Services, DXMessageBoxService and DialogService.
  3. DevExpress MVVM Framework. Interaction of ViewModels. IDocumentManagerService.
  4. DevExpress MVVM Framework. Introduction to POCO ViewModels.
  5. DevExpress MVVM Framework. Interaction of ViewModels. Messenger.
  6. THIS POST: DevExpress MVVM Framework. Using Scaffolding Wizards for building Views.
  7. DevExpress MVVM Framework. Data validation. Implementing IDataErrorInfo.
  8. DevExpress MVVM Framework. Using DataAnnotation attributes and DevExpress Fluent API.
  9. DevExpress MVVM Framework. Behaviors.
  10. DevExpress MVVM Framework. TaskbarButtonService, ApplicationJumpListService and NotificationService.
  11. DevExpress MVVM Framework. Asynchronous Commands.
  12. DevExpress MVVM Framework. Converters.


Today, we examine using ViewModels to automatically generate Views. Our application looks as follows.

001

When the application starts, the MainWindow shows the GridControl. The Ribbon provides some basic functionality to Add, Remove, or Modify a record, or Print the view.

Clicking Add or Modify opens a View in the detail tab.

002

While the second View is open, the RibbonControl displays its buttons: Save, Close, and Delete. Each save operation is specific to its tab. Changes are committed separately in each of the available tabs.

This simple layout can be automatically generated from ViewModels. You can try this yourself from the sample we’ve prepared. Download and open it from Code Example: E5001.

Notice the provided code of the sample for the model and ViewModels.

The model layer is three classes: Employee, EmployeeContext, and EmployeeContextInitializer.

Employee is a database entity. Entity Framework Code First creates the database during the application’s initial load.

EmployeeContext operates on the database with EF Code First.

EmployeeContextInitializer populates the database with predefined records.

There are two ViewModels.

The first is for the Employee table – EmployeeCollectionViewModel. Since it is a POCO class, its public and virtual properties are bindable and its public methods are available as commands. This ViewModel provides an Employees property for the database records. The available commands add, remove, or modify a record.

EmployeeViewModel is also a POCO class. A value for the Parameter property is necessary for each EmployeeViewModel instance. The parameter describes how the ViewModel operates on records: by creating a new record or modifying an existing one. The Save command commits changes. EmployeeViewModel also contains commands to remove a record or to close the corresponding View.

ViewModel to ViewModel interactions are mediated by Messenger. A message is sent when changes are saved in EmployeeViewModel. EmployeeCollectionViewModel catches this message and updates its View.

That’s it. Now, let’s generate the layout. Remove all the Views and the MainViewModel to follow the steps demonstrated in the video below.

Video 

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.