Ticket Q251089
Visible to All Users

Change css for specific group

created 15 years ago

Hello,
I've developed an XAF web application for maintaining attributes of a product object
I would like to be able to change the background of certain layout groups to different colors depending on the name or id of the layout group
The idea is to have a layout group in the detail view, which I can grab ahold of in a controller, and change it's background color to another color if possible
Can this be done?

Answers

created 15 years ago

Hi Mike,
You can implement this functionality by creating a DevExpress.ExpressApp.Web.Layout.LayoutGroupTemplate class descendant, and overriding its LayoutContentControls method to create layout group controls. For example, based on the base class implementation:

C#
public class ColoredLayoutGroupTemplate : LayoutGroupTemplate { public ColoredLayoutGroupTemplate() : base() { } protected override void LayoutContentControls(LayoutGroupTemplateContainer templateContainer, IList<System.Web.UI.Control> controlsToLayout) { if (templateContainer.ShowCaption && (!templateContainer.IsOnTabPage || (templateContainer.ParentGroupDirection == FlowDirection.Vertical))) { Literal child = new Literal(); child.Text = templateContainer.Caption; Table table = RenderHelper.CreateTable(); table.CssClass = "GroupHeader"; table.Rows.Add(new TableRow()); table.Rows[0].Cells.Add(new TableCell()); table.Rows[0].Cells[0].CssClass = "Label"; table.Rows[0].Cells[0].Controls.Add(child); if (templateContainer.HasHeaderImage) { ASPxImage image = new ASPxImage(); ASPxImageHelper.SetImageProperties(image, templateContainer.HeaderImageInfo); image.AlternateText = templateContainer.Caption; table.Rows[0].Cells.AddAt(0, new TableCell()); table.Rows[0].Cells[0].CssClass = "Image"; table.Rows[0].Cells[0].Controls.Add(image); } templateContainer.Controls.Add(table); } //--- create a colored panel, and add content controls into it Panel panel = new Panel(); string groupId = templateContainer.Info.GetAttributeValue("ID"); if (groupId.EndsWith("$red")) { panel.BackColor = System.Drawing.Color.Red; } foreach (System.Web.UI.Control control in controlsToLayout) { panel.Controls.Add(control); } templateContainer.Controls.Add(panel); templateContainer.Visible = templateContainer.IsContentVisible; } }

To use this template, create a detail view controller, and assign this template instance to the WebLayoutManager:

C#
public class ColoredGroupsViewController : ViewController { public ColoredGroupsViewController() { this.TargetViewType = ViewType.DetailView; } protected override void OnActivated() { base.OnActivated(); WebLayoutManager lm = ((DetailView)View).LayoutManager as WebLayoutManager; if (lm != null) lm.LayoutGroupTemplate = new ColoredLayoutGroupTemplate(); } }

A sample project, demonstrating this approach is in the attachment. Please let us know if this makes sense.
Thanks,
Michael.

    Comments (1)
    Apostolis Bekiaris (DevExpress) 12 years ago

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.