Back to Devexpress

Prism Adapters

wpf-117848-common-concepts-prism-adapters.md

latest6.6 KB
Original Source

Prism Adapters

  • Mar 01, 2024
  • 3 minutes to read

The DevExpress.Xpf.PrismAdapters.v25.2 assembly provides Prism 5 and Prism 6/7/8 adapters for the following controls:

The adapter instances are retrieved via the static AdapterFactory.Make method.

The code snippets below illustrate how to register the DevExpress Prism adapters in a Prism Unity bootstrapper.

Prism 5/6

csharp
class PrismBootstrapper : MefBootstrapper {
    protected override RegionAdapterMappings ConfigureRegionAdapterMappings() {
        var mappings = base.ConfigureRegionAdapterMappings();
        var factory = Container.GetExportedValue<IRegionBehaviorFactory>();
        mappings.RegisterMapping(typeof(DXTabControl),
            DevExpress.Xpf.Prism.AdapterFactory.Make<RegionAdapterBase<DXTabControl>>(factory));
        return mappings;
    }
    // ...
}
vb
Friend Class PrismBootstrapper
    Inherits MefBootstrapper

    Protected Overrides Function ConfigureRegionAdapterMappings() As RegionAdapterMappings
        Dim mappings = MyBase.ConfigureRegionAdapterMappings()
        Dim factory = Container.GetExportedValue(Of IRegionBehaviorFactory)()
        mappings.RegisterMapping(GetType(DXTabControl), DevExpress.Xpf.Prism.AdapterFactory.Make(Of RegionAdapterBase(Of DXTabControl))(factory))
        Return mappings
    End Function
    ' ...
End Class
csharp
using Microsoft.Practices.Unity;
class PrismBootstrapper : UnityBootstrapper {
    protected override RegionAdapterMappings ConfigureRegionAdapterMappings() {
        var mappings = base.ConfigureRegionAdapterMappings();
        var factory = Container.Resolve<IRegionBehaviorFactory>();
        mappings.RegisterMapping(typeof(DXTabControl),
            DevExpress.Xpf.Prism.AdapterFactory.Make<RegionAdapterBase<DXTabControl>>(factory));
        return mappings;
    }
    // ...
}
vb
Imports Microsoft.Practices.Unity
Friend Class PrismBootstrapper
    Inherits UnityBootstrapper

    Protected Overrides Function ConfigureRegionAdapterMappings() As RegionAdapterMappings
        Dim mappings = MyBase.ConfigureRegionAdapterMappings()
        Dim factory = Container.Resolve(Of IRegionBehaviorFactory)()
        mappings.RegisterMapping(GetType(DXTabControl), DevExpress.Xpf.Prism.AdapterFactory.Make(Of RegionAdapterBase(Of DXTabControl))(factory))
        Return mappings
    End Function
    ' ...
End Class

Prism 6

csharp
using Autofac;
class PrismBootstrapper : AutofacBootstrapper {
    protected override RegionAdapterMappings ConfigureRegionAdapterMappings() {
        var mappings = base.ConfigureRegionAdapterMappings();
        var factory = Container.Resolve<IRegionBehaviorFactory>();
        mappings.RegisterMapping(typeof(DXTabControl),
            DevExpress.Xpf.Prism.AdapterFactory.Make<RegionAdapterBase<DXTabControl>>(factory));
        return mappings;
    }
    // ...
}
vb
Imports Autofac
Friend Class PrismBootstrapper
    Inherits AutofacBootstrapper

    Protected Overrides Function ConfigureRegionAdapterMappings() As RegionAdapterMappings
        Dim mappings = MyBase.ConfigureRegionAdapterMappings()
        Dim factory = Container.Resolve(Of IRegionBehaviorFactory)()
        mappings.RegisterMapping(GetType(DXTabControl), DevExpress.Xpf.Prism.AdapterFactory.Make(Of RegionAdapterBase(Of DXTabControl))(factory))
        Return mappings
    End Function
    ' ...
End Class

Due to the Prism’s limitation in handling adapters for FrameworkContentElement descendants (specifically NavBarGroup and NavigationFrame), region names need to be specified in XAML using the DXRegionManager class. See the following code snippet:

xaml
<UserControl ...
    xmlns:dxprism="http://schemas.devexpress.com/winfx/2008/xaml/prism">
    <dxn:NavBarControl>
        <dxn:NavBarGroup dxprism:DXRegionManager.RegionName="NavBarControlRegion" />
    </dxn:NavBarControl>
</UserControl>

The DXRegionManager attempts to get the currently used version of Prism based on the registered adapters and loaded assemblies if the value of the static DXRegionManager.PrismVersion property is not specified. It is recommended to set this property to the appropriate value manually.

Prism 7/8

Note

Prism 8 support is available in versions 20.2.5 and newer.

csharp
public partial class App : PrismApplication {
    protected override void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings) {
        base.ConfigureRegionAdapterMappings(regionAdapterMappings);
        var factory = Container.Resolve<IRegionBehaviorFactory>();
        regionAdapterMappings.RegisterMapping(typeof(DXTabControl), DevExpress.Xpf.Prism.AdapterFactory.Make<RegionAdapterBase<DXTabControl>>(factory));
    }
}
vb
Partial Public Class App
    Inherits PrismApplication
    Protected Overrides Sub ConfigureRegionAdapterMappings(ByVal regionAdapterMappings As RegionAdapterMappings)
        MyBase.ConfigureRegionAdapterMappings(regionAdapterMappings)
        Dim factory = Container.Resolve(Of IRegionBehaviorFactory)()
        regionAdapterMappings.RegisterMapping(GetType(DXTabControl), AdapterFactory.Make(Of RegionAdapterBase(Of DXTabControl))(factory))
    End Sub
End Class

Examples

Prism - How to define Prism regions for various DXDocking elements

Using DXDocking for WPF in accordance with Composite Application Guidelines