Skip to main content

Ways to Access UI Elements and Their Controls

  • 7 minutes to read

This topic describes how to access UI elements such as Actions, View Items, List Editors, Property Editors, and their underlying controls.

Create a custom ViewController descendant (or a generic ViewController<ViewType> or ObjectViewController<ViewType, ObjectType>) and implement a solution from one of the following sections:

To access a Detail View in MasterDetailMode, use the EditView property.

Tasks with View Items and Property Editors

Get the ViewItem or Property Editor object

Use the CompositeView.FindItem(String) method in the ViewController.Activated event handler or overridden ViewController.OnActivated virtual method. The View Item’s name should match the corresponding Views | CompositeView | Items | ViewItem Model node’s ID property. The default Property Editor’s ID matches the property name.

Examples: Access the Dashboard Control | Open a Detail View When the Grid Row is Clicked in the Dashboard (WinForms and ASP.NET Web Forms)

Get View’s ViewItem objects collection

Use the CompositeView.Items property in the ViewController.Activated event handler or overridden ViewController.OnActivated virtual method.

Get all ViewItem objects of a specific type

Use the CompositeView.GetItems<T> method in the ViewController.Activated event handler or overridden ViewController.OnActivated virtual method.

Example: How to: Access the Report Preview Controls (ASP.NET Web Forms)

Access a View Item’s underlying control

Use the DetailViewExtensions.CustomizeViewItemControl(DetailView, Controller, Action<ViewItem>, String[]) method to access a control of a custom View Item.

Examples: Customize a Built-in Property Editor (WinForms) | Access the Settings of a Property Editor in a Detail View | Customize a Built-in Property Editor (Blazor) | Manage Button Visibility in a Blazor Lookup Property Editor

Access an embedded or nested View’s View Item

Use the NestedFrame.ViewItem property in the ViewController.Activated event handler or overridden ViewController.OnActivated virtual method.

Examples: How to: Initialize an Object Created Using the New Action | How to: Access Nested List View or Master Detail View Environment (ASP.NET Core Blazor and Windows Forms)

Customize a control of a Property Editor used both in a List and Detail View globally

Create a Property Editor’s descendant and customize it. Apply the custom Property Editor to target properties in Model Editor. You can also use this Property Editor for all properties of a specific type.

Examples: How to: Customize a Built-in Property Editor (WinForms | ASP.NET Web Forms)

Access a ViewItem’s parent View

Use the ViewItem.View property in the ViewController.Activated event handler or overridden ViewController.OnActivated virtual method.

Access the Layout Control and its items

If you want to customize layout elements that include ListPropertyEditors (for example, change a caption or options of a parent tab group or page control), use techniques demonstrated in the following learning materials:

Tasks with List Editors

Get the ListEditor object

Use the ListView.Editor property in the ViewController.Activated event handler or overridden ViewController.OnActivated virtual method.

Example: How to: Access the Grid Component in a List View

Access a List Editor’s underlying control

XAF includes various platform-specific List Editors. Each editor has properties, methods, and events to access an editor’s control. Handle the View.ControlsCreated, ListEditor.ControlsCreated, or ViewController.ViewControlsCreated event and use this API in the handler.

Examples: ListEditor.Control | How to: Access the Grid Component in a List View

Access a List Editor’s data cell control

There is no common solution for all List Editors. A List Editor can instantiate an internal Property Editor to propagate settings to underlying data cell controls in view and edit modes. Use List Editor’s members or customize its underlying control directly as described in the control’s documentation. If you want to customize a control globally for List and Detail Views, refer to the Customize a control of a Property Editor used both in a List and Detail View globally section.

Examples: DxGridListEditor.CustomizeViewItemControl (Blazor) | ComplexWebListEditor.FindPropertyEditor (Web Forms) | How to add an unbound column to GridListEditor (WinForms)

Tasks with Complex View Items

Access a control of an Action included in a Detail View layout

To access an ActionContainerViewItem‘s control, follow the directions from the Include an Action in a Detail View Layout topic.

Access a ListPropertyEditor’s control

  1. Use the CompositeView.FindItem(String) method in the ViewController.Activated event handler or overridden ViewController.OnActivated virtual method and cast the returned value to ListPropertyEditor.
  2. Handle the ListPropertyEditor‘s ControlCreated event.
  3. In the event handler, use the ListPropertyEditor‘s ListView property to get an underlying List View.
  4. Handle the underlying List View’s View.ControlsCreated event.
  5. In the event handler, use the ListView.Editor property to get an Editor.
  6. Use this Editor’s methods or properties (for example, WinColumnsListEditor.Grid) to access a control.
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Win.Editors;
using DevExpress.XtraGrid;
// ...
public class MyViewController : ViewController<ListView> {
    protected override void OnActivated() {
        base.OnActivated();
        ListPropertyEditor editorForCollectionProperty = View.FindItem("CollectionProperty") as ListPropertyEditor;
        editorForCollectionProperty.ControlCreated += (s, e) => {
            ListView nestedListView = ((ListPropertyEditor)s).ListView;
            nestedListView.ControlsCreated += (s1, e1) => {
                GridListEditor gridListEditor = ((ListView)s1).Editor as GridListEditor;
                if (gridListEditor != null) {
                    GridControl grid = gridListEditor.Grid;
                }
            };
        };
    }
}

Access a DetailPropertyEditor’s or DashboardViewItem’s control

  1. Use the CompositeView.FindItem(String) method in the ViewController.Activated event handler or overridden ViewController.OnActivated virtual method and cast the returned value to DetailPropertyEditor or DashboardViewItem.
  2. Handle the DetailPropertyEditor‘s or DashboardViewItem‘s ViewItem.ControlCreated event.
  3. In the event handler, use the DetailPropertyEditor‘s or DashboardViewItem‘s Frame property to access its Nested Frame.
  4. Use the NestedFrame.ViewItem property to get the Nested View’s View Item.
  5. Use the ViewItem.Control property to access a control.
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Editors;
// ...
public class MyViewController : ViewController<DetailView> {
    protected override void OnActivated() {
        base.OnActivated();
        DetailPropertyEditor editorForReferenceProperty =
        View.FindItem("ReferenceProperty") as DetailPropertyEditor;
        editorForReferenceProperty.ControlCreated += (s, e) => {
            NestedFrame nestedFrame = ((DetailPropertyEditor)s).Frame as NestedFrame;
            ViewItem nestedFrameViewItem = nestedFrame.ViewItem;
            if (nestedFrameViewItem.Control != null) { /* ... */ }
        };
    }
}

Tasks with Actions

Access an Action

Use the Frame.GetController<ControllerType>() method to get the Action’s Controller and the Controller.Actions property to get the Action from this Controller. Refer to the following help topic to determine an Action identifier: Determine an Action’s Controller and Identifier.

Example: Controller.Actions

Additional Information

  • XAF uses DevExpress WinForms and ASP.NET Web Forms controls in applications. You can access and customize these controls and widgets using their members. If you need assistance, submit a new ticket to the Support Center and specify the control’s platform in the Platform/Category field.
  • If you customize a control as described in the previous sections and this does not take effect, handle one of the following platform-specific events:

    WinForms

    ASP.NET Web Forms

    In ASP.NET Web Forms applications, you can also perform specific customizations on the client-side (see Client-Side Functionality Overview).

  • Most built-in View Items and Editors also expose properties to access a control (for example, GridListEditor.Grid, ASPxPropertyEditor.Editor, ASPxLookupPropertyEditor.DropDown, etc.). Traverse control hierarchy and access inner controls using an index (control.Controls[index]) only if there is no solution for your scenario in this topic and the control’s documentation.
  • If you customize an existing control’s Application Model options, this customization does not affect the control until its next creation. Customize the control directly or its corresponding Application Model options before the control is created and rendered.