The eXpressApp Framework allows View customization at design time, in code, and by end-users. You may wish to provide several customized variants of the same View, and allow an end-user to choose the desired View Variant at runtime. For instance, end-users may need to use different List View column sets and Detail View layouts in different scenarios. They may also need to use two List View modes: a single List View and a List View with a Detail View (see IModelListView.MasterDetailMode). XAF offers built-in implementation of this feature in the ViewVariantsModule, which is declared in the DevExpress.ExpessApp.ViewVariantsModule.v18.2.dll assembly. This topic will show you how to use this module to provide multiple versions of the same View. The following steps explain how to apply this module's capabilities. Additionally, you can refer to the Provide Several View Variants for End-Users tutorial.
To apply the View Variants module capabilities, add this module to your application or module project. For this purpose, use the Application Designer or Module Designer. Be sure to rebuild your solution after making changes in the Designer.
You can add a module in the Solution Wizard when creating a new XAF solution by selecting a module in the Choose Extra Modules step.
To see a demonstration of View Variants, you can run the Feature Center application that ships with XAF, and navigate to the View Variants item, or refer to the Feature Center demo online.
The View Variants module provides the ChangeVariantController View Controller. It contains the ChangeVariant Action, which allows end-users to select a View Variant to be displayed within the current Window (Frame). This Action is of the SingleChoiceAction type and has the ChangeVariant ID. Its items are specified by the Views | <View> | Variants node of the Application Model. The action is visible if there are two or more Variants child nodes in the current View node.
To add View Variants, do the following:
The following image illustrates how the varied View and its View Variants are organized in the Application Model.
The image below illustrates the ChangeVariant Action available in a WinForms application after following the steps above.
A variant can be chosen from the drop-down list. Variants are sorted according to their IModelNode.Index property values. The previously selected variant ID is stored with user customizations (in the Model.User.xafml file or in browser cookies).
View Variants can be also added to the Navigation. Set the IModelNavigationItemsVariantSettings.GenerateRelatedViewVariantsGroup property to true in the Model Editor.
The image below illustrates the result.
You can create a custom IVariantsProvider object that loads View Variants in a custom manner. Assign your VariantsProvider to the ViewVariantsModule.VariantsProvider property to replace the default ModelVariantsProvider that loads View Variants from the Application Model.