Change views in Silverlight using Prism

I am studying Prism and Silverlight, and now I am trying to create a simple application, but have run into a problem ...

I have a wrapper with 2 ContentControls, "MenuRegion" and "ContentRegion". The way I want it to work is that the user clicks on the item in the "MenuRegion" and then apororiate will appear in the ContentRegion, replacing any view that was previously there (all views in their projects, as if over which different people work with). All views displayed in the content area will be different.

I don’t know how to achieve this using the Prism model (I can do this if I want, but there will be a lot of code in View.cs and we would like to do it right). All the samples that I found there use the Tab control and load all the modules at the same time, which I am not trying to achieve. Is there any specific pattern that I should study, or any examples you know about this, could point me in the right direction?

+4
source share
1 answer

Give it a try.

Use RegionManager to add a view to your region:

regionManager.AddToRegion("ContentRegion", new MyViews.View1()); 

Then, if you want to replace this view, you can either delete the view:

 regionManager.Regions["ContentRegion"].Remove(view); 

Or scroll through the views in the area and delete them all:

  foreach (var view in regionManager.Regions["ContentRegion"].Views) { regionManager.Regions["ContentRegion"].Remove(view); } 

Your view model will be a good place to host such code. Use Unity to insert a region manager into the view model constructor.

+1
source

Source: https://habr.com/ru/post/1300476/


All Articles