WPF Prism Region inside a tab control isn't in the Region List

跟風遠走 提交于 2019-12-08 12:32:58

问题


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.

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.

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>

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);
 }

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?

Thanks for any help!


回答1:


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! :)

cheers. ste.



来源:https://stackoverflow.com/questions/10205063/wpf-prism-region-inside-a-tab-control-isnt-in-the-region-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!