expressappframework-112696-ui-construction-templates-template-customization.md
XAF built-in Templates generate UIs suitable for most business applications. You can modify these default templates or create fully custom templates at design time, or change template settings at runtime.
XAF determines the type of template to display based on TemplateContext. The following table lists the built-in XAF templates and their Contexts.
| Template | Blazor Template Class | WinForms Template Class | Template Context |
|---|---|---|---|
| Main Form Template (with a toolbar menu) | ApplicationWindowTemplate | LightStyleMainForm | ApplicationWindow |
| Main Ribbon Form Template | ApplicationRibbonWindowTemplate | LightStyleMainRibbonForm | ApplicationWindow |
| Detail Form Template (with a toolbar menu) | DetailFormTemplate | DetailFormV2 | View |
| Detail Ribbon Form Template | DetailRibbonFormTemplate | DetailRibbonFormV2 | View |
| Popup Window/Form Template | PopupWindowTemplate | PopupForm | PopupWindow |
| Nested Frame Template | NestedFrameTemplate | NestedFrameTemplateV2 | NestedFrame |
| Lookup Form Template | — | LookupForm | LookupWindow |
| Lookup Control Template | — | LookupControlTemplate | LookupControl |
| Logon Window Template | LogonWindowTemplate | LogonPopupForm | LogonWindow |
The DevExpress Template Kit allows you to add default XAF Template code to your application, customize it, and use your modified Templates instead of default Templates.
Add Template code in your project (SolutionName.Blazor.Server or SolutionName.Win) as described in the following help topic: Template Kit: Create a new item.
Modify the added template according to your needs.
Handle the XafApplication.CreateCustomTemplate event to make the application to use your Template instead of the default Template. In the event handler, assign your Template class to the Template property.
Handle the XafApplication.CustomizeTemplate event to customize a Template every time it is created.
The following code sample accesses the Popup Window Template and specifies the template’s size limits.
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Blazor.Templates;
public class LimitPopupSizeController : WindowController {
public LimitPopupSizeController() {
TargetWindowType = WindowType.Main;
}
protected override void OnActivated() {
base.OnActivated();
Application.CustomizeTemplate += Application_CustomizeTemplate;
}
void Application_CustomizeTemplate(object sender, CustomizeTemplateEventArgs e) {
if ((e.Context == TemplateContext.PopupWindow || e.Context == TemplateContext.LookupWindow)
&& e.Template is PopupWindowTemplate popupWindow) {
popupWindow.MaxWidth = "900px";
popupWindow.MaxHeight = "600px";
}
}
protected override void OnDeactivated() {
Application.CustomizeTemplate -= Application_CustomizeTemplate;
base.OnDeactivated();
}
}
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Win.Templates;
public class LimitPopupSizeController : WindowController {
public LimitPopupSizeController() {
TargetWindowType = WindowType.Main;
}
protected override void OnActivated() {
base.OnActivated();
Application.CustomizeTemplate += Application_CustomizeTemplate;
}
void Application_CustomizeTemplate(object sender, CustomizeTemplateEventArgs e) {
if (e.Context == TemplateContext.PopupWindow && e.Template is PopupFormBase popupForm) {
popupForm.MaximumSize = new Size(900, 600);
}
}
protected override void OnDeactivated() {
base.OnDeactivated();
Application.CustomizeTemplate -= Application_CustomizeTemplate;
}
}