This example implements a View Controller that accesses layout controls and customizes them as required. In particular, the second tab in the tab control should become active when the detail form is opened.
WinForms
ASP.NET Core Blazor
Implementation Details
- This functionality is implemented in the WinCustomizeTabControlViewController.cs and BlazorCustomizeTabControlViewController.cs classes, added to the WinForms and Blazor application projects respectively. Copy these classes to the corresponding projects in your test solution.
- To identify the layout element by the MyTabbedGroup string, make sure this identifier is specified under the Views | YourBusinessObject_DetailView | Layout node in the Model Editor (invoked for the YourSolutionName.Module/Model.DesignedDiffs.xafml file).
Files to Review
Documentation
More Examples
- XAF - How to show the number of nested List View items in tab captions
- How to set active tab in a Web DetailView layout after executing an Action
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
C#using System;
using DevExpress.ExpressApp;
using DevExpress.XtraLayout;
using DevExpress.ExpressApp.Win.Layout;
namespace AccessLayout.Win {
public class WinCustomizeTabControlViewController : ViewController<DetailView> {
TabbedControlGroup tabbedGroup;
WinLayoutManager layoutManager;
protected override void OnActivated() {
base.OnActivated();
layoutManager = (WinLayoutManager)View.LayoutManager;
layoutManager.ItemCreated += OnItemCreated;
layoutManager.LayoutCreated += OnLayoutCreated;
}
void OnItemCreated(object sender, ItemCreatedEventArgs e) {
// Check this Id in the AccessLayoutEF.Module/Model.DesignedDiffs.xafml file
if (e.ModelLayoutElement.Id == "MyTabbedGroup") {
tabbedGroup = (TabbedControlGroup)e.Item;
}
}
private void OnLayoutCreated(object sender, EventArgs e) {
if (tabbedGroup != null) {
tabbedGroup.SelectedTabPageIndex = 1;
}
}
protected override void OnDeactivated() {
if (layoutManager != null) {
layoutManager.ItemCreated -= OnItemCreated;
layoutManager.LayoutCreated -= OnLayoutCreated;
layoutManager = null;
}
tabbedGroup = null;
base.OnDeactivated();
}
}
}
C#using System;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Blazor.Components.Models;
using Microsoft.AspNetCore.Components;
using DevExpress.ExpressApp.Blazor.Layout;
namespace AccessLayoutEF.Blazor {
public class BlazorCustomizeTabControlViewController : ViewController<DetailView> {
BlazorLayoutManager layoutManager;
protected override void OnActivated() {
base.OnActivated();
layoutManager = (BlazorLayoutManager)View.LayoutManager;
layoutManager.ItemCreated += OnItemCreated;
}
private void OnItemCreated(object sender, BlazorLayoutManager.ItemCreatedEventArgs e) {
if (e.ModelLayoutElement.Id == "MyTabbedGroup" && e.LayoutControlItem is DxFormLayoutTabPagesModel tabbedGroup) {
tabbedGroup.ActiveTabIndex = 1;
tabbedGroup.ActiveTabIndexChanged = EventCallback.Factory.Create<int>(this, index => tabbedGroup.ActiveTabIndex = index);
}
}
protected override void OnDeactivated() {
if (layoutManager is not null) {
layoutManager.ItemCreated -= OnItemCreated;
layoutManager = null;
}
base.OnDeactivated();
}
}
}