Hi
How do I implement Expandable Groups in the Layout Editor?
Regards
Andrew
We have closed this ticket because another page addresses its subject:
How do I provide the capability to collapse or expand layout groups and persist their state?How to implement expandable layout groups in Detail View layout (WinForms)
Answers approved by DevExpress Support
v19.2+
With XAF v19.2, the new platform-agnostic options - IModelLayoutGroup.IsCollapsibleGroup and IModelLayoutGroup.IsGroupCollapsed - are available to control this behavior for both WinForms and ASP.NET apps. For more information on how it affects the former ASP.NET Application Model options, see this breaking change.
For older versions or custom-tailored implementations when the standard solution is not suitable, consider the options from How do I provide the capability to collapse or expand layout groups and persist their state?
Hi Andrew,
In the simplest way, you can refer to the Access the Layout Control in Code help topic, to access the layout control and set the LayoutGroup.ExpandButtonVisible property for the required layout groups.
This is the code of a controller I used to do this:
C#using DevExpress.XtraLayout;
namespace WinSolution.Module {
public partial class MyLayoutViewController : ViewController {
public MyLayoutViewController() {
InitializeComponent();
RegisterActions(components);
this.TargetObjectType = typeof(WinSolution.Module.MyPerson);
this.TargetViewType = DevExpress.ExpressApp.ViewType.DetailView;
}
protected override void OnActivated() {
base.OnActivated();
View.ControlsCreated += new EventHandler(View_ControlsCreated);
}
protected override void OnDeactivating() {
base.OnDeactivating();
View.ControlsCreated -= new EventHandler(View_ControlsCreated);
}
void View_ControlsCreated(object sender, EventArgs e) {
((System.Windows.Forms.Control)View.Control).HandleCreated += new EventHandler(MyLayoutViewController_HandleCreated);
}
void MyLayoutViewController_HandleCreated(object sender, EventArgs e) {
DevExpress.XtraLayout.LayoutControl layoutControl = ((DevExpress.XtraLayout.LayoutControl)((DetailView)View).Control);
layoutControl.BeginUpdate();
try {
foreach (object item in layoutControl.Items) {
if (item is LayoutControlGroup) {
((LayoutControlGroup)item).ExpandButtonVisible = true;
((LayoutControlGroup)item).Expanded = true;
((LayoutControlGroup)item).ExpandButtonLocation = DevExpress.Utils.GroupElementLocation.AfterText;
((LayoutControlGroup)item).ExpandOnDoubleClick = true;
}
}
} finally {
layoutControl.EndUpdate();
}
}
}
}
My sample project is also attached. Please let me know if this solution suits your needs. Otherwise, please describe your requirements in more detail.
Thanks,
Dennis
Other Answers
Hello,
The following code can be used to do the same customization:
C#using System;
using DevExpress.XtraLayout;
using DevExpress.ExpressApp;
using System.Collections.Generic;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Win.Layout;
namespace MainDemo.Module.Win {
public class Q101774 : ViewController<DetailView> {
private ISupportAppearanceCustomization layoutManager;
protected override void OnActivated() {
base.OnActivated();
layoutManager = (ISupportAppearanceCustomization)View.LayoutManager;
layoutManager.CustomizeAppearance += new EventHandler<CustomizeAppearanceEventArgs>(layoutManager_CustomizeAppearance);
}
private void layoutManager_CustomizeAppearance(object sender, CustomizeAppearanceEventArgs e) {
LayoutControlGroup lg = ((WinLayoutItemAppearanceAdapter)e.Item).Item as LayoutControlGroup;
if (lg != null) {
lg.ExpandButtonVisible = true;
lg.Expanded = true;
lg.ExpandButtonLocation = DevExpress.Utils.GroupElementLocation.BeforeText;
lg.ExpandOnDoubleClick = true;
}
}
protected override void OnDeactivated() {
layoutManager.CustomizeAppearance -= new EventHandler<CustomizeAppearanceEventArgs>(layoutManager_CustomizeAppearance);
base.OnDeactivated();
}
}
}
Attached is also a small video. It is also possible to extend the application model to save the expandable state.
Thanks,
Dennis
FYI - I tried both methods but the original method that loops through layoutgroups after the handlecreated event has much higher performance when rendering the detailview than using the CustomizeAppearance event. Cut my view load times in half or more.
I've attached a complete WinForms sample to the How do I provide the capability to collapse or expand layout groups and persist their state? ticket (see its WinForms section for the main implementation steps). I hope you find this information helpful.
Hello,
Sorry for the delay in processing your request. We're working on it, and will post our resolution as soon as it's ready.
Thank you for your patience.
Thanks,
Dennis