Prism 4: Unloading from the region?

How to unload a view from the Prism area?

I am writing a WPF Prism application with a ribbon control in the shell. The Main Ribbon tab contains the RibbonHomeTabRegion area, which includes one of my modules (let's call ModuleA): RibbonGroup . It works great.

When the user moves from module A, the RibbonGroup must be unloaded from RibbonHomeTabRegion . I do not replace RibbonGroup with another view - the region must be empty.

EDIT: I rewrote this part of the question:

When I try to delete a view, I get the error message "Region does not contain the specified view." So, I wrote the following code to remove any kind in the region:

 // Get the regions views var regionManager = ServiceLocator.Current.GetInstance<IRegionManager>(); var ribbonHomeTabRegion = regionManager.Regions["RibbonHomeTabRegion"]; var views = ribbonHomeTabRegion.Views; // Unload the views foreach (var view in views) { ribbonHomeTabRegion.Remove(view); } 

I am still getting the same error that tells me that there is something pretty basic that I am doing wrong.

Can someone point me in the right direction? Thank you for your help.

+4
source share
3 answers

I found my answer, although I cannot say that I fully understand it. I used IRegionManager.RequestNavigate () to insert the RibbonGroup into the Main Ribbon tab, for example:

 // Load RibbonGroup into Navigator pane var noteListNavigator = new Uri("NoteListRibbonGroup", UriKind.Relative); regionManager.RequestNavigate("RibbonHomeTabRegion", noteListNavigator); 

I changed the code to enter the view by registering it in this area, for example:

 // Load Ribbon Group into Home tab regionManager.RegisterViewWithRegion("RibbonHomeTabRegion", typeof(NoteListRibbonGroup)); 

Now I can remove RibbonGroup with this code:

 if(ribbonHomeTabRegion.Views.Contains(this)) { ribbonHomeTabRegion.Remove(this); } 

So how you do this, apparently, matters. If you want to delete the view, add it using the area manager

+4
source

Is it possible that you have a RegionAdapter that wraps a view inside another view before adding it? ribbonHomeTabRegion must have a property with a collection of views - is there anything inside it?

0
source

StockTraderRI Project A Microsoft example contains the following example of removing views from a scope in a ViewModel.

 private void RemoveOrdersView() { IRegion region = this._regionManager.Regions[RegionNames.ActionRegion]; object ordersView = region.GetView("OrdersView"); if (ordersView != null) { region.Remove(ordersView); } } 
0
source

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


All Articles