expressappframework-113047-ui-construction-templates-how-to-distribute-custom-templates-with-modules.md
XAF uses default Templates when constructing Windows Forms UIs. You can customize them. Approaches for customization are defined in the Template Customization and How to: Create a Custom WinForms Ribbon Template topics. Once you have developed a custom Template, you may need to use it in several applications. The appropriate way to distribute Windows Forms Templates is to add them to a module that will then be added to the required Windows Forms applications. This topic demonstrates how to do this. ASP.NET Core Blazor templates can be easily distributed, as is. You can add them to an ASP.NET Core Blazor application project replacing the defaults.
When constructing a Windows Forms UI, the WinApplication class instance uses its Frame Template Factory to create a Template that is appropriate in the current context. A Frame Template Factory is a class that implements the IFrameTemplateFactory interface. This interface exposes a single method, CreateTemplate, that gets the current Template context as a parameter. XAF has a base class that implements this interface, FrameTemplateFactoryBase, and its descendant, DefaultLightStyleFrameTemplateFactory. The base class exposes abstract methods that are called by the CreateTemplate method, dependent on the passed Template context. They are: CreateNestedFrameTemplate, CreatePopupWindowTemplate, CreateLookupControlTemplate, CreateLookupWindowTemplate, CreateApplicationWindowTemplate and CreateViewTemplate. The DefaultLightStyleFrameTemplateFactory class overrides these methods to create the default XAF Templates.
To make an application use custom Templates, do the following:
Add the custom Templates to the module project to be distributed.
Implement a Frame Template Factory class in the module to be distributed.
Set the custom Frame Template Factory for the application.
Compile the module project and add it to the required application project (see Application Solution Structure).