开发者

Add multiple elements to a Prism region

I'm using Prism with the Microsoft WPF Ribbon, and everything works quite well, but I have a problem with contextual tabs. I define the contextual tabs in my Shell.xaml:

<Ribbon:Ribbon.ContextualTabGroups>
    <Ribbon:RibbonContextualTabGroup Header="CTG1" Visibility="Visible" Background="Red" />
    <Ribbon:RibbonContextualTabGroup Header="CTG2" Visibility="Visible" Background="Blue" />
    <Ribbon:RibbonContextualTabGroup Header="CTG3" Visibility="Visible" Background="Purple" />
    <Ribbon:RibbonContextualTabGroup Header="CTG4" Visibility="Visible" Background="Green" />
    <Ribbon:RibbonContextualTabGroup Header="CTG5" Visibility="Visible" Background="Orange" />
    <Ribbon:RibbonContextualTabGroup Header="CTG6" Visibility="Visible" Background="Violet" />
</Ribbon:Ribbon.ContextualTabGroups>

This way in my modules I can refer to those contextual tab groups and it works great. But I would like to define the contextualtabgroups in the modules. I thought of defining a region:

<Ribbon:Ribbon.ContextualTabGroups x:Name="RibbonContextualTabs" prism:RegionManager.RegionName="RibbonContextualTabs" />

And then in my module I would have a UserControl that inherited RibbonContextualTabGroup for each one and register those with the region... Is there a way to just define a usercontrol with some ContextualTabGroups and add them as a whole? For example:

<Ribbon:RibbonContextualTabContainer x:Class="Views.ContextualTabsView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:Ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary">
    <Ribbon:RibbonContextualTabGroup Header="CTG1" Visibilit开发者_Go百科y="Visible" Background="Red" />
    <Ribbon:RibbonContextualTabGroup Header="CTG2" Visibility="Visible" Background="Blue" />
    <Ribbon:RibbonContextualTabGroup Header="CTG3" Visibility="Visible" Background="Purple" />
</Ribbon:RibbonContextualTabContainer>

as ContextualTabsView.xaml and in my module make a

_regionManager.RegisterViewWithRegion("RibbonContextualTabs", typeof (ContextualTabsView));

I don't know if I made myself clear of what I'm trying to accomplish, but I would appreciate any help.

Thanks.


Some time ago i faced the same problem (but i was using the Teleriks Ribbon Bar). I couldn't find any way to add tabs from the modules, or at less from XAML.

What i did was a service like this:

public class RibbonService
{
    public PrioritySet<RibbonTab> Tabs { get; private set; }
    public PrioritySet<object> QuickAccess { get; private set; }
    public PrioritySet<ContextualGroup> ContextualGroup { get; private set; }
}

this clases has the following structure:

Add multiple elements to a Prism region

The key here is the class PrioritySet, to make it simpler, it is just a collection where each item has a priority asociated.

Now if a service like this is registered on your framework, then from the modules you could add the Tabs. Remember that your shell project needs to get the RibbonService and then bind the collection of items to the Tabs property - note that PrioritySet implements INotifyCollectionChanged, so if the ribbon is binded it's items will be updated automatically.

Also with this you could get some intresting stuff, as composing the tabs from the service. For example one module may need to add only one button to the ribbon, this could be easily done doing

_ribbonService.Tabs.Add(new RibbonButton(){Header = "Button", Icon = new Uri("icon.png")})

In my app, i have Tabs > Groups > Buttons so every module has full control over the Ribbon. Note also that from the modules you could add all the items that you want, but the module can't remove an item from the ribbon aat less it have a reference to it, or be the one that created it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜