NuGet package | Owin.Framework.Pages.Html |
GitHub source | OwinFramework.Pages.Html |
Region elements define and area of a page that contains content. The content can be defined by a component, layout, template set, or localizable Html. The region can bind to a list of objects and repeat the content for each object in the list. The region can also introduce a new data binding scope that affects how the content within the region resolves its data needs.
In many situations you can define the regions you need by decorating an empty class with attributes. This is illustrated below:
[IsRegion("header")] [Style("height: 90px; width:100%; padding:10px; background: gray; color: whitesmoke; clear: both;")] [UsesLayout("header")] internal class HeaderRegion { }
In this example the [IsRegion()] attribute defines the name of the region. This name can be used to refer to the region in other page elements. The [Style()] attribute defines some custom styling for the <div> element that is rendered by the region, and the [UsesLayout()] attribute specifies a layout to render inside the <div>.
The following attributes can be attached to a region define the region's behavior.
If you are unable to achieve the effect you are looking for by decorating empty classes with attributes, then you can also make your region class inherit from the built-in Region class and override the virtual methods to fully customize the behavior as illustrated in the example below:
private class RegionExample : Region { public RegionExample(IRegionDependenciesFactory dependencies) : base(dependencies) { WriteOpen = w => { w.WriteOpenTag("ul"); w.WriteLine(); }; WriteClose = w => { w.WriteCloseTag("ul"); w.WriteLine(); }; WriteChildOpen = w => { w.WriteOpenTag("li"); w.WriteLine(); }; WriteChildClose = w => { w.WriteCloseTag("li"); w.WriteLine(); }; RepeatType = typeof(NewsItem); } }
If you are creating a distributable package, or creating reusable packages within your application, these packages can build regions using the fluent syntax provided by the Fluent Builder. This is illustarted by the example below:
[IsPackage("regions")] public class RegionsPackage : OwinFramework.Pages.Framework.Runtime.Package { public RegionsPackage(IPackageDependenciesFactory dependencies) : base(dependencies) { } [Container("ul")] [Repeat(typeof(NewsItem), null, "li")] private class Region1 : Region { public Region1(IRegionDependenciesFactory dependencies) : base(dependencies) { } } public override IPackage Build(IFluentBuilder fluentBuilder) { fluentBuilder.BuildUpRegion(new Region1(Dependencies.RegionDependenciesFactory)) .Name("region1") .BindTo("breaking-news") .ClassNames("news", "breaking") .Build(); return this; } }