D J
D J

Reputation: 7028

WPF + PRISM How to change the region at runtime

I need to load the region based on the RegionName binded. Somehing like

 <ContentControl cal:RegionManager.RegionName="{Binding CustomRegionName}"
                    Grid.Column="2"/>

All the regions are registered properly. If I change the value of CustomRegionName the region never changes. How can I do this?

Upvotes: 6

Views: 3961

Answers (1)

The Unculled Badger
The Unculled Badger

Reputation: 760

This behaviour is because the region is already loaded into the visual tree. Could you alter your app slightly so that you maintain the region name but load multiple views into the region. This way you would be able to select which view is active in the region and dynamically change the display of the content control by using the IRegionViewManager and IRegion interfaces i.e

IRegion region = regionManager.Regions["RegionName"];
object view = container.Resolve<SomeView>();
object view2 = container.Resolve<SomeView2>();

region.Add(view);
region.Add(view2);

Then where you want to show a particular view somewhere else Inject the IRegionManager and then call

region.Activate(whichever view);

Upvotes: 5

Related Questions