Prism WPF 动态区域 [英] Prism WPF Dynamic Regions
问题描述
假设我们有一个带有模块 A 和 B 的 Prism 7 应用程序.主窗口有一个选项卡控件和两个按钮,它们将模块 A 或 B 添加到选项卡控件.我为 Tab Control 项目创建了一个绑定并实现了一个项目模板,其中包括 Prism Region,其名称绑定到项目名称.
Let's say we have a Prism 7 application with modules A and B. The main window has a Tab Control and two buttons, which add either module A or B to the Tab Control. I created a binding for the Tab Control items and implemented an item template, which includes Prism Region, whose name is bound to the item name.
<TabControl ItemsSource="{Binding Tabs}">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<ContentControl prism:RegionManager.RegionName="{Binding}" />
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
我面临的问题是区域名称似乎没有改变,即如果我首先添加模块 A,接下来的所有按钮点击都会添加模块 A,反之亦然.在我之前的问题 Prism WPF Binding RegionManager.RegionName 中,我被解释说我不应该绑定RegionManger.RegionName
,所以我的问题是,我应该如何实现需求?
The problem I am facing is that the region name doesn't seem to change, i.e. if I first add Module A, all the next button clicks will add Module A and vice versa. In my previous question Prism WPF Binding RegionManager.RegionName I was explained that I shouldn't bind the RegionManger.RegionName
, so my question is, how should I implement the requirements?
存储库链接:https://github.com/moisejbraver/ModulesTest
推荐答案
这是我处理带有棱镜区域的选项卡控件的方式,我认为这对您也有帮助.
This is the way i handle tab controls with prism regions, i think this is helpful for you too.
<TabControl prism:RegionManager.RegionName="{x:Static local:RegionNames.AdvancedSetup}">
<TabControl.ItemContainerStyle>
<Style TargetType="TabItem">
<Setter Property="Visibility" Value="{Binding DataContext.IsAvailable, Converter={coverters:BooleanToVisibilityConverter}}"/>
<Setter Property="Header" Value="{Binding DataContext.Name}"/>
</Style>
</TabControl.ItemContainerStyle>
</TabControl>
然后我将所有选项卡注册到每个模块的 OnInitialized 函数中的同一区域.
Then i register all my tabs to the same region in OnInitialized function of each module.
regionManager.RegisterViewWithRegion(RegionNames.AdvancedSetup, setupType);
我制作了一个界面,所有选项卡的视图模型都会实现,它包含
I've made an interface which all viewmodels of tabs will implement, it contains
- 标签名称
- 标签是否可见.
您可能需要根据需要更改一些详细信息.
You may need to change some details based on your need.
这篇关于Prism WPF 动态区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!