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?
Change css for specific group
Answers
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.