Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

wpf - PRISM - Reuse of Views With Child Regions - Can It Be Done?

I'm a bit of a PRISM newbie, but I've read the help documentation and can't seem to find out how to achieve the following (this is a WPF application)

I have a Shell (Window) that has 2 regions called 'region1' and 'region2'. in the Initialize method of my one and only module, I am registering the same view with each region:

regionViewRegistry.RegisterViewWithRegion("Region1", typeof(View1));
regionViewRegistry.RegisterViewWithRegion("Region2", typeof(View1));

and when I run it everything is OK at this point as it creates 2 individual instances of View1, and places one in each region.

Now in View1 I have declared its own region for injecting small child views

<ItemsControl Name="MainRegion" cal:RegionManager.RegionName="MainRegion" />

Now when I run my very simple PRISM app I get the following exception message:

"Region with the given name is already registered: MainRegion"

which suggests that I cannot have multiple instances of the same view if that view declares its own regions.

Is this correct ?

seems like a huge limitation.

I want my application to be highly modular, and to have view compose themselves of oother views (via regions) etc.

Or have I mis-read the documentation?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can create a separation of shell-level regions with regions created by module views by using RegionScope. Any region you create without a scope is "global" and having two regions with the same name in the same scope isn't supported.

You can read more about Region Scopes in this MSDN article: http://msdn.microsoft.com/en-us/magazine/cc785479.aspx#id0090126


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...