Log In
[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Collapse]eXpressApp Framework
 [Expand]Getting Started
 [Expand]Design-Time Features
 [Collapse]Task-Based Help
  [Expand]Business Model Design
  [Expand]Application Model
  [Expand]List Editors
  [Expand]Property Editors
    How to: Access the Bar Manager
    How to: Access the Document Manager
    How to: Access the Ribbon Control
    How to: Create a Custom WinForms Ribbon Template
    How to: Create a Custom WinForms Standard Template
    How to: Customize an ASP.NET Template
    How to: Distribute Custom Templates with Modules
  [Expand]Scheduler and Notifications
  [Expand]Miscellaneous UI Customizations
  Frequently Asked Questions (FAQ)
 [Expand]API Reference
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
This documentation page describes implementations made in our v17.2 release cycle. To learn about functionality shipping with v18.1, navigate to our updated help file experience at docs.devexpress.com. Learn More

How to: Create a Custom WinForms Standard Template

XAF provides two form styles of WinForms applications: Standard and Ribbon. Your application's form style can be selected using the IModelOptionsWin.FormStyle property of the Options node. This example demonstrates how to modify the default template of the Standard form style - create a main menu item and place an Action into it. If your FormStyle is Ribbon, please refer to the How to: Create a Custom WinForms Ribbon Template article instead.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T196002.

Consider the following Action located on the View menu:

By default, you can place an Action into an existing predefined menu only. The steps below demonstrate how you can place this Action into a custom location within the menu bar.

  1. Open the Template Gallery for the WinForms application project and add the XAF WinForms Templates | Detail Form Template project item.

  2. In the Main Menu bar of the detail form designer, click the [Add] button and choose Menu (BarSubItem). Then, give a name for the new menu, for example, "My Actions".


    You can create a complex hierarchy of sub-menus using nested BarSubItem items.

  3. Open the newly created menu, click the [Add] button and select Inplace LinkContainer (BarLinkContainerExltem). Name the link container. The primary container is usually named after its menu. Name it "My Actions".


    You can also add an Action Container to the status bar. In the Status Bar Menu of the detail form designer, click the [Add] button and select Inplace Link Container (BarLinkContainerExltem). Then, specify the caption for the new link container, for example, "My Status Actions".

  4. At the bottom part of the designer, focus the barManager control, click its smart tag, then select Run Designer.

  5. As a result, the XAF BarManager Designer (an XAF-specific extension of the Bar Manager Designer) is invoked. In the navigation panel at the left part of the designer, select the XAF Action Controls | Action Containers page. To make an action container from a link container, drag "My Actions" item from the Bar Container Controls list to Action Containers. After that, close the designer.


    If you want to additionally place an action container to a status bar, drag the "My Status Actions" item from the Bar Container Controls list to Action Containers.

  6. Change the category of the Action that you want to place into the created menu. Use the same value that was specified in step 3 (e.g., My Actions). If your Action is created in code, you can pass the category to the Action's constructor.

    Alternatively, you can use the ActionBase.Category property in code or in the Controller designer, or the IModelAction.Category property or the ActionsDesign | Actions | MyAction node in the Model Editor.

  7. Finally, you should replace the default Template with the custom Template. Edit the application project's Program.cs (Program.vb) file and handle the XafApplication.CreateCustomTemplate event.

The following image illustrates the result.


You can localize this custom Template using the approach described in the How to: Localize a WinForms Template topic.

Expanded Important Notes

  • In this example, it is assumed that you use the Tabbed MDI mode MdiShowViewStrategy, which is the default for any XAF solution created from the Solution Wizard. In this mode, the visible bar menu elements are merged from the Detail Form and Main Form templates. In other modes, it may be required to customize the Main Form instead of the Detail Form, or both these templates, depending on your particular scenario. To create a custom Main Form, use the XAF WinForms Templates | Main Form Template template to create the MainForm1 (the process is similar to the one described above). Then, use the following code of the CreateCustomTemplate event handler.

  • If users of your application can choose between the Ribbon and Standard form styles using the IModelOptionsWin.FormStyle property, then you may need to check this property value in the CreateCustomTemplate event handler before specifying a custom ribbon template.

  • If your XAF application was created in a version prior to 14.2, and then upgraded, please ensure that the WinApplication.UseOldTemplates property is set to false.

Expanded See Also

Is this topic helpful?​​​​​​​