region
is a named injectable portion of the UI where other components can inject their on content. A region is attached to a DependencyObject
on the UI, depending on the type of the object the region is attached to the region behavior changes. Radical has 3 different main region types:IContentRegion<T>
: a content region is thought for a ContentPresenter
or a ContentControl
UIElement, it can host one single content at a time and each time a new content is set the previous one will be removed;IElementsRegion<T>
: an elements region can host multiple contents at a time, it is thought for a Panel
UIElement, so each WPF control that inherits from panel, such as the StackPanel
, can be used with an IElementsRegion
; Content from an IElementsRegion
can be added or removed and will be available depending on the logic implemented by the underlying UIElement;ISwitchingElementsRegion<T>
: a switching elements region is an element region that, other than being able to host multiple elements at a time, has also the concept of an active element that can change over time; a typical sample is a TabControl
where each TabItem
can be seen;IDisposable
they will be disposed;IExpectViewClosedCallback
they will receive a callback notification;IRegionManager
implementation;RegionManager
is automatically created by the UI Composition engine as soon as a region is added to a View
, a RegionManager
is bound to a WPF Window
instance.logical tree
:UIElement
that requires injection:rg
namespace declaration pointing to the Radical region namespace http://schemas.radicalframework.com/windows/presentation/regions
;UIElement
via the Region
attached property of the RegionService
element;RegionManager
to host the region, RegionManager whose lifecycle is bound to the lifecycle of the hosting Window
. If the region is defined in a UserControl
the RegionManager lifecycle will be bound to the lifecycle of the Window
hosting the UserControl.ViewLoaded
message is broadcasted to notify that the View has been loaded:ViewLoaded
message, overriding the OnShouldHandle
method to define a rule to handle only the ViewLoaded event related to the View we are interested in.Handle
method we utilize:RegionService
to determine is the View has a RegionManager
;partial view
, a partial view is a View
, and if defined its ViewModel
, that can be automatically picked up and injected based on a set of conventions:MyRegion
;*.Presentation.Partials.*
;View
in a specific region
, is to decorate the View
class with the InjectViewInRegionAttribute
:MyUserControlView
into the region named "MyRegion".IContentRegion<T>
, IElementsRegion<T>
and ISwitchingElementsRegion<T>
. Each region type has a default implementation.ContentPresenterRegion
is a IContentRegion<ContentPresenter>
that can be applied to a ContentPresenter UIElement
.PanelRegion
is a IElementsRegion<Panel>
, given that a Panel
is an abstract class, this region can be used with any UIElement
that inherits from Panel
, such as a StackPanel
.TabControlRegion
is an implementation of the ISwitchingElementsRegion<TabControl>
and can be used with a TabControl
.