Thursday, July 31, 2008

Infragistics TabGroupPane Region Adapter for CompositeWPF (Prism) Applications

This is my first contribution (more to come soon) to the WPF world ! A Region Adapter for the Infragistics TabGroupPane* component.

For those not familiar with Composite WPF:
  • A View is a unit that encapsulates a portion of the UI and is kept as decoupled as possible from other parts of the application.
  • A Region is a container that holds Views to be displayed.
  • A Region Adapter adapts a Region to a WPF Control, thus displaying the actual contents of the associated Views.

I started adapting TabGroupPane since it was an immediate need for a prototype I am coding. As the prototype continues evolving, I think I'll be end up adapting other components of xamDockManager and maybe others of Net Advantage for WPF.

*TabGroupPane is a component of xamDockManager - A powerful docking and layout
management control for WPF (http://www.infragistics.com/dotnet/netadvantage/wpf/xamdockmanager.aspx)


Usage

  • Register the TabGroupPane region adapter mapping in the Bootstrapper as shown in the code below:

    protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
    {

    RegionAdapterMappings mappings = base.ConfigureRegionAdapterMappings();

    mappings.RegisterMapping(typeof(TabGroupPane), new TabGroupPaneRegionAdapter());

    return mappings;

    }

  • Add the TabGroupPane to your Shell/View XAML (you have to declare the namespace on the top of the file):

    <igDock:XamDockManager Grid.Row="1" x:Name="dockManager">
    <igDock:SplitPane >
    <igDock:TabGroupPane Name="TabGroupPane1"
    cal:RegionManager.RegionName="{x:Static infrastructure:RegionNames.Editor}"/>
    </igDock:SplitPane>
    <
    /igDock:XamDockManager>

  • To add views, just obtain the region and call the Add method as you do with other regions:

    IRegion editorRegion = RegionManager.Regions[RegionNames.Editor];
    ITabGroupPaneMetadata tabGroupPaneMetadata = new TabGroupPaneMetadata();
    tabGroupPaneMetadata.Header=”Header #1”;

    MyView view = new MyView();

    view
    .SetTabGroupPaneMetadata(tabGroupPaneMetadata);

    editorRegion.Add(
    view);

    editorRegion.Activate(
    view);


    Notice that
    in the preceding code I am also setting the TabGroupPaneMetadata attached property to the view (via Extensions Methods). This attached property is used by the TabGroupPaneRegionAdapter to set the Header property displayed on the associated TabGroupPane item.

Disclaimer
This code is provided "AS IS" with no warranties, and confers no rights.


Download
You can get the TabGroupPaneRegionAdapter by downloading the latest change set of the CompositeWPF Contrib source control.