How to get the current active view in a region using PRISM?

prism regions
prism 7 navigation wpf
prism 7 wpf example
prism wpf
prism region context
prism wpf example
prism registerviewwithregion
prism view injection

I know that i can get all the registered views in a region with :

var vs = mRegionManager.Regions[RegionNames.MainRegionStatic].Views.ToList();

and i can see there is the following code :

mRegionManager.Regions[RegionNames.MainRegionStatic].ActiveViews

which is giving a list of Active View, but I'm having my region attached to a ContentControl which always has a single ActiveView. Am i misunderstood or is there a way to get the single active view?


var singleView = regionManager.Regions["MyRegion"].ActiveViews.FirstOrDefault();

c#, By using our site, you acknowledge that you have read and I was facing an issue where I want to retrieve existing/active ViewModels from the Prism runtime. Find(Type viewModelType) { var shellContext = Application.Current. object Find(IRegion region, Type viewModelType) { foreach (var view in  5 Answers 5. active oldest votes. 4. If your region is a ContentControl or derives from ContentControl, then there can only be one active view at a time, and you only need to activate the search view on the region.


var singleView = regionManager.Regions["MyRegion"].ActiveViews.FirstOrDefault();

This is not correct, as it will just bring whatever view that got activated first. not the currently active/visible view.

Can't find a direct solution though, that doesn't involve custom implementation on View or ViewModel.

Prism find active/existing ViewModel, This adapter adapts controls of type System. takes the object to adapt and returns a new region associated with the adapted control. This region allows multiple active views. throughout the application's lifetime, so make sure you do not keep references to possibly  When you click on a link, it loads the view of this category in the right panel and a small left panel shows the tasks available for this category. Simple. Basically, what I want to do is to have a "contextalized" status bar. If you are in a view where you need to be connected, the status bar should show you state.


Well, you could use the NavigationService Journal. It takes record of all the navigation that takes place in your application. So, you can get the name of the view like this:

string name = mRegionManager.Regions[RegionNames.MainRegionStatic].NavigationService.Journal.CurrentEntry.Uri;

Then you can get the view like this:

mRegionManager.Regions[RegionNames.MainRegionStatic].GetView(name);

Sweet Right? :)

Navigation Using the Prism Library for WPF, But what if you want to completely replace the View in a Region with a Views to Regions and using the Region's Activate method to make a Writing the code to ensure that the right Views are added to the right region, and the right View is active, Current.GetInstance<Microsoft.Practices.Prism.Regions. Navigating Between Views in WPF and Prism. Prism's Navigation API makes it a lot easier to swap Views in and out of regions in your Window -- assuming you give Prism enough information to do the job right. By Peter Vogel; 08/07/2012


Extending the Prism Library 5.0 for WPF, If you are just getting started with Prism, it is recommended that you start from the first sample, and Make your commands IActiveAware to invoke only the active command Region Navigation, See how to implement basic region navigation. A ContentControl region can have only one active view at any given time, an ItemsControl region can have multiple active-views. A Selector though not a ContentControl, also have one active view, it is when we switch between tabs, that Prism de-activates old view, and activates the new selected view.


Navigating Between Views in WPF and Prism -- Visual Studio , To work with Regions effectively in a Prism based WPF application, we must understand For more learning about Prism, please have a look at Prism Basic RegisterMapping(typeof(ContentControl), ServiceLocator.Current. Activation and Deactivation are used to mark a View active and deactivated. Internally Prism uses ServiceLocator and resolves the view with the key “viewName”, and use the resolved view to navigate the region. The difference between adding a view and navigating to a view is that “Add” literally adds the view to the region; when we navigate to a view, we entirely replace the region with the view.


PrismLibrary/Prism-Samples-Wpf: Samples that , Using the application, a user can view current investments and related news Using a region removes the need for the module to have any specific reference to the UI Regions can contain views that are active or inactive. If the currently active view in the region implements this interface (or its view model), its OnNavigatedFrom method is called before navigation takes place. The OnNavigatedFrom method allows the previous view to save any state or to prepare for its deactivation or removal from the UI, for example, to save any changes that the user has made to a web service or database.