Creating a classic collection view

To display a collection of records in the UI.WPF.Views project, please follow the following steps :

  • Under the Collection Views folder, create a new UserControl
  • Modify the new class’ namespace so that it matches the value of the _viewsNamespace field of the MainWindow class.
  • Make your class inherit from the CollectionViewUserControl<TModel, TViewModel, TDetailView> class, which is implemented in the WPF.Core namespace.
  • Replace the generic parameters with types that relate to the entities you want to display (e.g. : to display a collection of Person entities, inherit from CollectionViewUserControl<Person, PersonViewModelBase, PersonDetailView>).
  • In the base constructor call, you can inject filter parameters.
  • In the constructor, call the LoadData method with your datagrid instance as a parameter.

In a next post, I’ll show you how to use the alternate version of the CollectionViewUserControl class in order to either improve performance or just to have different ViewModel types between your collection and detail views.

Advertisements