Skip to main content
A newer version of this page is available. .

Provide Several View Variants for End-Users

  • 4 minutes to read

In this lesson, you will learn how to provide several customized variants of the same View, and allow an end-user to choose a desired View variant at runtime. Variants can be applied to both List Views and Detail Views. In this lesson, the Contact List View will be used. Two variants of this List View will be constructed via the Module Editor. To switch between these View variants, the special ChangeVariant Action will be used. To add this Action, the ViewVariants module will be referenced in the application.

Note

Before proceeding, take a moment to review the following lessons.

  • Add the View Variants module to your MySolution.Module project. Find the Module.cs (Module.vb) file in the MySolution.Module project displayed in the Solution Explorer, and double-click this file. The Module Designer will be invoked. In the Toolbox, navigate to the DX.18.2: XAF Modules tab. Drag the ViewVariantsModule item from this tab to the Designer’s Required Modules section.

    Tutorial_EM_Lesson2_0

  • Rebuild your solution so that the changes made in the Module Designer are loaded to the Application Model.
  • Invoke the Model Editor for the MySolution.Module project. Right-click the Views node and select Add… | ListView.

    Tutorial_EM_Lesson2_0_1

    For the new node, set the Id property to “Contact_ListView_AllColumns” and the ModelClass property to “Contact”.

    Tutorial_EM_Lesson2_0_2

  • Right-click the newly created node and select Generate content. Columns will be generated using information on the specified class (BOModel | Contact node) and its ancestors. Leave these columns as is. This List View will represent the complete variant for the Contact List View.

    Tutorial_EM_Lesson2_1

  • Right-click the Views node and select Add… | ListView. For the new node, set the Id property to “Contact_ListView_Varied” and the ModelClass property to “Contact”. Do not generate content for the new node.

    Tutorial_EM_Lesson2_2_1

  • Expand the newly added Contact_ListView_Varied node, right-click the Variants child node and select Add… | Variant.

    Tutorial_EM_Lesson2_2_2

  • For the new node, set the View property to “Contact_ListView”, and set the Id and Caption properties to “Few columns”.

    Tutorial_EM_Lesson2_2_3

  • Right-click the Variants node and select Add… | Variant. For the new node, set the View property to “Contact_ListView_AllColumns”, and set the Id and Caption properties to “All columns”.

    Tutorial_EM_Lesson2_2_4

  • Navigate to the NavigationItems | Items | Default | Items | Contact node. Its View property, specifying the View displayed when choosing the Contact navigation item, is “Contact_ListView” by default. Change it to “Contact_ListView_Varied”.

    Tutorial_EM_Lesson2_2_5

  • Run the WinForms or ASP.NET application. Select the Contact item in the navigation control. For the displayed Contact List View, the ChangeVariant Action will be activated. This Action’s items represent the view variants specified in the Model Editor.

    Tutorial_EM_Lesson2_3

    Note

    You can use the Index property to specify the sort order of variants in the ChangeVariant Action drop-down list. Additionally, you can set the Current property of the Variants node to specify the default variant.

  • Optionally, you can add view variants to the navigation control. For this purpose, invoke the Model Editor and set the GenerateRelatedViewVariantsGroup property of the NavigationItems node to true.

    Tutorial_EM_Lesson2_5

    Note

    Ensure that the IModelChoiceActionItemChildItemsDisplayStyle.ChildItemsDisplayStyle property of the current navigation group node is set to List (see Change Style of Navigation Items). Otherwise, the view variants will not be added to the navigation control in the WinForms application.

    As a result, the Contact navigation item will expose child items for each view variant.

    Tutorial_EM_Lesson2_6

You can see the changes made in this lesson in the Model Editor invoked for the Model.DesignedDiffs.xafml file, located in the Main Demo | MainDemo.Module project. The MainDemo application is installed in %PUBLIC%\Documents\DevExpress Demos 18.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version of this demo is available online at https://demos.devexpress.com/XAF/MainDemo.

 

Next Lesson: Audit Object Changes

See Also