Nov 29, 2008 at 12:46 PM
I want to implement tool bars in my project and ran across this adapter class.

How is this used?  I would think perhaps adapter for ToolBarTray would be useful too.  Has anyone used ToolBarTray as a region?

Willem Meints, I think you added this adapter to this project, would you shed some light please?

Dec 29, 2008 at 4:00 PM

we've used the panel adaptor - declared in the shell as below

        <!--Tool Bars-->
        <ToolBarTray Margin="0,0,0,0" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4" Style="{DynamicResource MainToolBarTray}">
                <ToolBarPanel Orientation="Horizontal" x:Name="MainToolbar" cal:RegionManager.RegionName="{x:Static inf:RegionNames.MainToolbarRegion}"/>

then adding controls to the panel (Configuration toolbar is a horizontal stackpanel with some buttons in):

            IAppListViewPresentationModel appListpresentationModel = _container.Resolve<IAppListViewPresentationModel>();
            IRegion mainToolbarRegion = _regionManager.Regions[RegionNames.MainToolbarRegion];

            // add config toolbar

The only problem I have with this at the moment is that seperators between buttons in my stackpanel don't have the right style.. I may post a question about that on here..

hope it helps

Jan 20, 2009 at 8:41 AM

I agree that a RegionAdapter for the ToolbarTray would be very useful! I created a UIExtensionService which does provide use (beside some other stuff) with the ability to add whole ToolBars to a predefined ToolBarTray.

For adding individual Buttons to the MainToolBar (similar to the example given by Trev) I just define a Region inside a ToolBar without using the ToolBarPanel... so I'm not really sure what usage the ToolBarPanelRegionAdapter has.

Here is the XAML code:

<ToolBarTray Name="ToolBarTray" DockPanel.Dock="Top" IsLocked="False">
            <ToolBar cal:RegionManager.RegionName="{x:Static UI:RegionNames.MainToolBarRegion}" Visibility="{Binding RelativeSource={RelativeSource Self}, Path=Items.Count, Converter={StaticResource ToolBarVisibilityConverter}}" />

To automatically make the MainToolBar invisible (Collapsed) I bind the Visibility property to the Items.Count Property of the ToolBar using a converter...

Saw similar styling behaviour (styles not beeing applied to buttons) when wrapping some Controls inside a Grid-Panel before adding it to the ToolBar. Any ideas on this?

Oct 12, 2009 at 3:02 PM
Edited Oct 12, 2009 at 4:02 PM

Hi guys!

I've created a ToolBarTrayRegionAdapter, and it works successfully (it based on this article Prism - Creating a Custom Region Adapter for Ribbon by Prajeesh):

The Solution:


public class ToolBarTrayRegionAdapter : RegionAdapterBase<ToolBarTray>
        public ToolBarTrayRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
            : base(regionBehaviorFactory)
        { }
        private ToolBarTray _Instance;
        protected override void Adapt(IRegion region, ToolBarTray toolBarTray)
            _Instance = toolBarTray;
            region.ActiveViews.CollectionChanged += new NotifyCollectionChangedEventHandler(
                (sender, e) => 
                    switch (e.Action)
                        case NotifyCollectionChangedAction.Add:
                            foreach (ToolBar toolBar in e.NewItems)

                        case NotifyCollectionChangedAction.Remove:
                            foreach (ToolBar toolBar in e.NewItems)
                    //region.ActiveViews.ToList().ForEach(t => toolBarTray.ToolBars.Add(t as ToolBar)); throws an exception, but it works without this line 

        protected override IRegion CreateRegion()
            return new AllActiveRegion();
protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
            RegionAdapterMappings mappings = base.ConfigureRegionAdapterMappings();
            mappings.RegisterMapping(typeof(ToolBarTray), this.Container.Resolve<ToolBarTrayRegionAdapter>());
            return mappings;
<ToolBarTray Name="ToolBarPanelRegion" cal:RegionManager.RegionName="{x:Static infrastructure:RegionNames.ToolBarPanelRegion}"/>
<ToolBar x:Class="UI.Modules.Views.ToolBarView.SearchToolBar"
    <Button Content="Search"></Button>
public partial class SearchToolBar : ToolBar
        public SearchToolBar()
Try it :)
Jan 14, 2011 at 9:51 PM

Thanks for your post (from over one year ago).

I discovered one defect. In the adapt method, for case remove, the code should iterate over e.OldItems rather than e.NewItems.