Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Prism how to have duplicate views inside a region

Tags:

wpf

prism

I'm currently working with the Tab control and have created a region so it will become my host.

what I'm trying to do is add the same view to a region twice.. you may ask why? and its because the application is going a simple chat app - there will many instances of the view but each will have different information.

my code so far;;

        IConversationDetailsPresentationModel convDetailsView1 =
            this.Container.Resolve<IConversationDetailsPresentationModel>();

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

        manager.RegisterViewWithRegion("TabRegion", () => convDetailsView1);

        IConversationDetailsPresentationModel convDetailsView2 =
            this.Container.Resolve<IConversationDetailsPresentationModel>();

        manager.RegisterViewWithRegion("TabRegion", () => convDetailsView2);

And my views are registered with unity like so;;

   this.Container.RegisterType<IConversationDetailsPresentationModel,                   ConversationDetailsPresentationModel>(
            new TransientLifetimeManager());

        this.Container.RegisterType<IConversationDetailsView, ConversationDetailsView>(
            new TransientLifetimeManager());

also, my XAML

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

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

Edit : my actual question is this.. Is it possible to have duplicate views inside a region? When I try it currently I get an exception about it already being registered.. what I really need is to bypass this or possible create a region that will allow it.

thanks for any help!!

cheers. ste.

like image 887
Steoates Avatar asked Apr 17 '12 09:04

Steoates


1 Answers

Try this.

IRegion TabRegion =  manager.Regions["TabRegion"];

tabRegion.Add(convDetailsView1);
tabRegion.Add(convDetailsView2);
like image 164
Rik van den Berg Avatar answered Sep 22 '22 12:09

Rik van den Berg