expressappframework-120092-ui-construction-ways-to-access-ui-elements-and-their-controls-ways-to-access-ui-elements-and-their-controls.md
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.
Use the CompositeView.FindItem(String) method in the overridden ViewController.OnActivated virtual method (recommended) or the ViewController.Activated event handler. 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)
Use the CompositeView.Items property in the overridden ViewController.OnActivated virtual method (recommended) or the ViewController.Activated event handler.
Use the CompositeView.GetItems<T> method overridden ViewController.OnActivated virtual method (recommended) or the ViewController.Activated event handler.
To access a custom View Item inside a custom ViewController, use the following CustomizeViewItemControl methods:
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
Use the NestedFrame.ViewItem property in the overridden ViewController.OnActivated virtual method (recommended) or the ViewController.Activated event handler.
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)
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 (ASP.NET Core Blazor | WinForms)
Use the ViewItem.View property overridden ViewController.OnActivated virtual method (recommended) or the ViewController.Activated event handler.
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:
Use the ListView.Editor property in the overridden ViewController.OnActivated virtual method (recommended) or the ViewController.Activated event handler.
Example : How to: Access the Grid Component in a List View
XAF includes various platform-specific List Editors. Each editor has properties, methods, and events to access an editor’s control such as ListEditor.Control. Use the overridden ViewController.OnViewControlsCreated virtual method (recommended) or the ViewController.ViewControlsCreated | View.ControlsCreated event handler.
Examples :
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 : How to add an unbound column to GridListEditor (WinForms)
You can customize the TreeListEditor and CategorizedListEditor List Editors or the TreeList control exposed via the List Editor’s ListEditor.Control property.
To access a List Editor in code, create a View Controller and handle its ViewController.ViewControlsCreated event or override the OnViewControlsCreated protected method.
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Blazor.Editors;
namespace YourSolutionName.Blazor.Server.Controllers;
public class ColumnResizeModeViewController : ViewController<ListView> {
protected override void OnViewControlsCreated() {
base.OnViewControlsCreated();
if (View.Editor is DxTreeListEditor treeListEditor) {
treeListEditor.TreeListModel.ColumnResizeMode =
DevExpress.Blazor.TreeListColumnResizeMode.ColumnsContainer;
}
}
}
using DevExpress.ExpressApp.TreeListEditors.Win;
using DevExpress.XtraTreeList;
using DevExpress.Persistent.Base.General;
namespace YourSolutionName.Win.Controllers;
public partial class TreeListController : ViewController {
public TreeListController() {
TargetViewType = ViewType.ListView;
TargetObjectType = typeof(ITreeNode);
}
protected override void OnViewControlsCreated() {
base.OnViewControlsCreated();
ListView view = (ListView)View;
TreeListEditor listEditor = (TreeListEditor)view.Editor;
TreeList treeList = listEditor.TreeList;
// Access the TreeList object here.
}
}
using DevExpress.ExpressApp.TreeListEditors.Win;
using DevExpress.XtraTreeList;
using DevExpress.Persistent.Base.General;
namespace YourSolutionName.Win.Controllers;
public partial class CategorizedListController : ViewController {
public CategorizedListController() {
TargetViewType = ViewType.ListView;
TargetObjectType = typeof(ICategorizedItem);
}
protected override void OnViewControlsCreated() {
ListView view = (ListView)View;
CategorizedListEditor listEditor = (CategorizedListEditor)view.Editor;
ListView categoriesListView = listEditor.CategoriesListView;
TreeListEditor treeListEditor = (TreeListEditor)categoriesListView.Editor;
TreeList treeList = treeListEditor.TreeList;
// Implement the required changes here.
}
}
Note
For more information about accessing the Scheduler control, refer to the following topic: How to: Access the Scheduler Control in Code.
To access an ActionContainerViewItem‘s control, follow the directions from the How to Add an Unbound Control (Button) to the Form Layout in an XAF View (with a Built-in ActionContainerViewItem) topic.
ListPropertyEditor‘s control and its nested List View.ListPropertyEditor, DetailPropertyEditor, DashboardViewItem), those control is a NestedFrame’s template and embeds a nested View with own controls.DetailPropertyEditor and the CustomizeViewItemControl(DashboardView, Controller, Action<ViewItem>) method to access DashboardViewItem controls.DetailPropertyEditor‘s or DashboardViewItem‘s Frame property to access the NestedFrame object and its template control.DetailPropertyEditor‘s or DashboardViewItem‘s ViewItem.ControlCreated event.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
In Windows Forms, a View Item control or a List Editor control may not be ready for customization immediately after creation. If the technique described in this topic does not have the desired effect, handle platform-specific events listed below.
ASP.NET Core BlazorXAF ASP.NET Core Blazor apps do no need specialized events to customize their underlying controls. However, you must use an EventCallback-based approach instead of handling regular C# events for underlying Blazor UI controls. In rare cases, you can also handle the DevExpress.ExpressApp.Blazor.Editors.Models.DxGridModel.ComponentInstanceCaptured event to access underlying component instance and its full API. For more information, refer to the Handle Component Events section.Windows Forms:
The Control object’s HandleCreated, VisibleChanged, or ParentChanged event.
You can also handle Load or any similar event if the current control type exposes it.
Contact our Support Center if you need help.
If you customize an existing control’s Application Model options, this customization does not affect the control until its next creation. Customize the control or its corresponding Application Model options before XAF creates and renders the control. For more information, refer to the following topic: Read and Set Values for Built-in Application Model Nodes in Code.