Ways to Access UI Elements and Their Controls

This topic describes how to access UI elements such as 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 the following sections:

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 Editor Settings | How to: Access the Dashboard Control


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.

Examples: How to: Access the ASPxDocumentViewer and ASPxWebDocumentViewer Controls | How to: Access the ReportViewer Control


Access a View Item's underlying control

Use the ViewItem.Control property in the ViewItem.ControlCreated event handler. You can also use the overridden ViewItem.OnControlCreated virtual method to access a control of a custom View Item.

Examples: Access Editor Settings | Access Mobile Editor Settings


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 Master Detail View and Nested List View Environment


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 | Mobile)


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

Follow the steps from the View Items Layout Customization topic's Access the Layout Control section.


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.

Examples: Access Grid Control Properties | Access List Control Properties


Access a List Editor's underlying control

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

Example: ListEditor.Control | How to: Access the List Editor's Control


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: ComplexWebListEditor.FindPropertyEditor | How to: Edit a Reference Property in the Batch Edit Mode | How to add an unbound column to GridListEditor


Tasks with Complex View Items

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

To access an ActionContainerViewItem's control, follow the directions from the How to: Include an Action to 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;
        editorForAggregatedReferenceProperty.ControlCreated += (s, e) => {
            NestedFrame nestedFrame = ((DetailPropertyEditor)s).Frame as NestedFrame;
            ViewItem nestedFrameViewItem = nestedFrame.ViewItem;
            if (nestedFrameViewItem.Control != null) { /* ... */ }
        };
    }
}

Additional Information

  • XAF uses DevExpress WinForms, ASP.NET controls and DevExtreme Mobile widgets 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

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

  • Most built-in View Items and Editors also provide properties for 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.