Ways to Access UI Elements and Their Controls
- 9 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:
- Tasks with View Items and Property Editors
- Tasks with List Editors
- Tasks with Complex View Items
- Tasks with Actions
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 ListPropertyEditor
s (for example, change a caption or options of a parent tab group or page control), use techniques demonstrated in the following learning materials:
- Access Form Layout Control in XAF DetailView and DashboardView (help topic)
- XAF - How to show the number of nested List View items in tab captions (example)
#Tasks with List Editors
#Get the ListEditor object
Use the ListView.Editor property in the overridden ViewController.OnActivated
, View.ControlsCreated
, or OnViewControlsCreated
virtual methods.
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
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: DxGridListEditorBase.CustomizeViewItemControl (Blazor) | ComplexWebListEditor.FindPropertyEditor (Web Forms) | How to add an unbound column to GridListEditor (WinForms)
#Access a Control in Tree List Editors
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.
#Access DxTreeListEditor (ASP.NET Core Blazor)
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;
}
}
}
#Access TreeListEditor (Windows Forms)
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.
}
}
#Access CategorizedListEditor (Windows Forms)
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.
}
}
#Access ASPxTreeListEditor (ASP.NET Web Forms)
XAF ASPxTreeList
integration code is not designed to immediately show the new value of a Boolean property if it was changed on the server side. XAF does not immediately display updated values when changed via an Action. To reflect the changes without refreshing the page, use the following code:
using DevExpress.Web.ASPxTreeList;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.TreeListEditors.Web;
// ...
public class RemoveTreeListDataCellTemplateController : ViewController {
public RemoveTreeListDataCellTemplateController() : base() { }
protected override void OnActivated() {
base.OnActivated();
ListView listView = View as ListView;
if (listView != null && listView.Editor != null) {
listView.Editor.ControlsCreated += Editor_ControlsCreated;
}
}
void Editor_ControlsCreated(object sender, EventArgs e) {
ASPxTreeListEditor treeListEditor = sender as ASPxTreeListEditor;
if (treeListEditor != null) {
TreeListDataColumn column =
treeListEditor.TreeList.Columns["BoolProperty"] as TreeListDataColumn;
if (column != null) {
column.DataCellTemplate = null;
}
}
}
}
This way the ASPxTreeList
control uses the TreeListDataColumn to show Boolean values. For more information, refer to the following topic: TreeListDataColumn.DataCellTemplate.
Since Controllers are implemented in modules, add a reference to the TreeList Editors module to the required module. Set a reference to the DevExpress.XtraTreeList.v25.1.dll assembly as well.
#Access a Scheduler Control in Code
Note
For more information about accessing the Scheduler control, refer to the following topic: How to: Access the Scheduler Control in Code.
#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 How to Add an Unbound Control (Button) to the Form Layout in an XAF View (with a Built-in ActionContainerViewItem) topic.
#Access a ListPropertyEditor’s control
- Use the CompositeView.FindItem(String) method in the ViewController.Activated event handler or overridden
ViewController.OnActivated
virtual method and cast the returned value toListPropertyEditor
. - Handle the
ListPropertyEditor
‘sControlCreated
event. - In the event handler, use the
ListPropertyEditor
‘sListView
property to get an underlying List View. - Handle the underlying List View’s View.ControlsCreated event.
- In the event handler, use the ListView.Editor property to get an Editor.
- 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
- Use the CompositeView.FindItem(String) method in the ViewController.Activated event handler or overridden
ViewController.OnActivated
virtual method and cast the returned value toDetailPropertyEditor
orDashboardViewItem
. - Handle the
DetailPropertyEditor
‘s orDashboardViewItem
‘s ViewItem.ControlCreated event. - In the event handler, use the
DetailPropertyEditor
‘s orDashboardViewItem
‘sFrame
property to access its Nested Frame. - Use the NestedFrame.ViewItem property to get the Nested View’s View Item.
- 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:
Win
Forms ASP.
NET Web Forms - Control.
Handle Created - Control.
Visible Changed - Control.
Parent Changed - The Load or similar event if the current control type exposes it
- Control.
- Control.
Load - Control.
Init - Web
Window. event (the currentPage Pre Render Web
object is available using the static WebWindow Window. property)Current Request Window
- Control.
In ASP.NET Web Forms applications, you can also perform specific customizations on the client-side (see Client-Side Functionality Overview).
- Control.
- 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.