将多个元素添加到 Prism 区域

发布于 2024-12-01 16:54:51 字数 2088 浏览 2 评论 0原文

我将 Prism 与 Microsoft WPF Ribbon 一起使用,一切都运行良好,但我在上下文选项卡上遇到了问题。我在 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>

这样,在我的模块中,我可以引用这些上下文选项卡组,并且效果很好。但我想在模块中定义 contextualtabgroups。我想到定义一个区域:

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

然后在我的模块中,我将有一个 UserControl,它为每个控件继承 RibbonContextualTabGroup 并将其注册到该区域...有没有一种方法可以仅使用一些 ContextualTabGroup 定义用户控件并将它们添加为一个整体?例如:

<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" Visibility="Visible" Background="Red" />
    <Ribbon:RibbonContextualTabGroup Header="CTG2" Visibility="Visible" Background="Blue" />
    <Ribbon:RibbonContextualTabGroup Header="CTG3" Visibility="Visible" Background="Purple" />
</Ribbon:RibbonContextualTabContainer>

作为 ContextualTabsView.xaml 并在我的模块中 make a

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

我不知道我是否清楚地说明了我想要完成的任务,但我将不胜感激任何帮助。

谢谢。

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" Visibility="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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

星星的轨迹 2024-12-08 16:54:51

前段时间我遇到了同样的问题(但我使用的是 Teleriks Ribbon Bar)。我找不到任何从模块添加选项卡的方法,或者至少从 XAML 中添加选项卡的方法。

我所做的是这样的服务:

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

这个类具有以下结构:

diagram for the clases

这里的关键是类 PrioritySet,为了简单起见,它只是一个集合,其中每个项目都有一个关联的优先级。

现在,如果在您的框架上注册了这样的服务,那么您可以从模块中添加选项卡。请记住,您的 shell 项目需要获取 RibbonService,然后将项目集合绑定到 Tabs 属性 - 请注意,PrioritySet 实现 INotifyCollectionChanged,因此如果绑定了功能区,则其项目将自动更新。

此外,您还可以获得一些有趣的东西,例如从服务中编写选项卡。例如,一个模块可能只需要向功能区添加一个按钮,这可以轻松完成

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

在我的应用程序中,我有 Tabs >组>按钮使每个模块都可以完全控制功能区。另请注意,您可以从模块中添加所需的所有项目,但模块无法从功能区中删除项目,除非它引用了该项目,或者是创建该项目的项目。

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:

diagram for the clases above

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文