Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF + PRISM How to change the region at runtime

Tags:

wpf

prism

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?

like image 791
D J Avatar asked Dec 04 '12 02:12

D J


People also ask

What is region in Prism?

Prism regions are essentially named placeholders within which views can be displayed. Any control in the application's UI can be a declared a region by simply adding a RegionName attached property to it, as shown here.

What is WPF region?

A region is a placeholder in the application UI into which modules are injected. You can mark a control as a region using any of the following approaches. Set the UIRegion. Region attached property. XAML.

What is Shell in Prism?

The shell is usually the MainWindow or MainPage. Implement this method by returning an instance of your application's shell class. In a Prism application, you can create the shell object, or resolve it from the container, depending on your application's requirements.

What is Prism framework in WPF?

Prism is a Microsoft framework which assists you to design and build rich, flexible, and easy-to-maintain complex applications specific to Windows Presentation Foundation (WPF) desktop applications, Silverlight Rich Internet Applications (RIAs), and Windows Phone applications.


1 Answers

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);
like image 127
The Unculled Badger Avatar answered Oct 29 '22 04:10

The Unculled Badger