选项卡控件内的WPF Prism Region不在Region列表中 [英] WPF Prism Region inside a tab control isn't in the Region List

查看:334
本文介绍了选项卡控件内的WPF Prism Region不在Region列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有附加区域的选项卡控件,并且我的选项卡控件内部还有一个内容控件,该内容带有另一个区域。

I've got a tab control with a region attached to it and I've also got a content control inside my tab controls content with another region.

我遇到的问题是-如果我调用RegisterViewWithRegion,它将视图添加到该区域没有问题(第一次,如果交换选项卡,则会出现问题)。但这不是很灵活,我正在寻找一种更好的方法。

The problem I'm having is - if I call RegisterViewWithRegion it adds the view to the region no problem (first time that is, get issues if you swap tabs). But this isn't very flexible and I'm looking for a better way to do that.

当我查看IRegionManager.Regions时,也只能看到-两个顶级区域。我看不到我的子区域 TabContentRegion 。有没有一种方法可以注册它,以便我可以以通常的方式添加视图并激活它们?

When I look inside IRegionManager.Regions as well - I can only see the two top level regions. I cant see my sub region TabContentRegion. Is there a way to register this so I can just work in the usual way with adding views and activating them?

   <TabControl TabStripPlacement="Left"
            Width="Auto"
            Height="Auto"
            cal:RegionManager.RegionName="TabRegion"
            Name="TabRegion"
            SelectedItem="{Binding SelectedTab}">
    <TabControl.ContentTemplate>
        <DataTemplate>

            <ContentControls:TransitionContentControl 
                cal:RegionManager.RegionName="TabContentRegion" />

        </DataTemplate>
    </TabControl.ContentTemplate>
</TabControl>

此代码将视图添加到TabRegion

This code adds the views to the TabRegion

 public void Load()
 {
     IConfigurationDetailsPresentationModel convDetailsView1 =
         this.Container.Resolve<IConfigurationDetailsPresentationModel>();

     IRegionManager manager = this.Container.Resolve<IRegionManager>();
     manager.RegisterViewWithRegion("TabRegion", () => convDetailsView1);

     IConversationDetailsPresentationModel conversationDetails = 
         this.Container.Resolve<IConversationDetailsPresentationModel>();
     manager.RegisterViewWithRegion("TabRegion", () => conversationDetails);
 }

然后这是我用来实际显示视图的代码TabContentRegion

Then this is the code I've been using to actually display the view in the TabContentRegion

 public IPresentationModel SelectedTab
 {
     get { return _selectedTab; }
     set
     {
         _selectedTab = value;

         IRegionManager service = this.Container.Resolve<IRegionManager>();

         if (service != null)
         {
             service.RegisterViewWithRegion(
                 "TabContentRegion",
                 () => _selectedTab.View);
         }
     }
 }

您可以看到-有点过时了,不太有效。有任何想法我做错了吗?

As you can see - it's a bit janky and doesn't quite work. Any ideas what I'm doing wrong?

感谢您的帮助!

推荐答案

在玩了很多游戏之后,我终于找到答案了!

After alot of playing and googling I finally came across and answer!

因为该区域位于数据模板中,所以人们认为棱镜的标准行为不会被采纳并使用区域代码进行注册。

because the region was inside a datatemplate, that ment that prisms standard behaviours wouldn't pick it up and register it with the region manager.

使用提供的代码此处,它帮助我解决了该问题并正常进行了! :)

using the code provided here it helped me to fix this and carry on as normal! :)

欢呼。
ste。

cheers. ste.

这篇关于选项卡控件内的WPF Prism Region不在Region列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆