Recognize active view

Topics: Prism v1, Prism v2 - Silverlight 2, Prism v2 - Silverlight 3, Prism v2 - Silverlight 4, Prism v2 - WPF 3.5, Prism v2 - WPF 4, Prism v4 - Silverlight 4, Prism v4 - WPF 4
Oct 28, 2010 at 8:39 AM

Related to this post ( i would like to ask a "cleaner" question:

What is the better way to recognize the active view in my shell?
what kind of pattern did you suggest? I have not found nothing on QuickStart projects or documentation.


Oct 29, 2010 at 6:19 PM
Edited Oct 29, 2010 at 6:25 PM


A Region instance provides you a collection of its active views. It provides a collection because depending on the region type that you are using, you could display either multiple views (ItemsControl/Selector exposed as a region) or only one view (ContentControl exposed as a region).  Fore more information on this topic you could take a look at the following documentation sections on MSDN:

Therefore, for achieving this scenario you could use the following code (pseudo-code): 

var yourActiveView = regionManager.Regions["MainRegion"].ActiveViews;

Hope this helps.

Fernando Antivero

Oct 30, 2010 at 6:44 AM

To get the first active view you can do:

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

To be notified when the set of ActiveViews changes:

regionManager.Regions[""].ActiveViews.CollectionChanged += (sender, e) =>
    // process e.Action and e.NewItems...


Oct 30, 2010 at 4:53 PM

Thankyou fro your replies.

Thankyou verymuch for your help but what do you think about a more structured managment of active/focused view?
A toolbar is related to all the application but in one application there could be more regionsso...more than one active view.
Anyway only one region is "realy" active because it have the input focus in a child control
So i was thinkling to "something" that can live "crosswise" respect regions and all application views.
Something that can manage the real active view and notify events to toolbar or to other objects.
I am just thinking and searching a way to solve this problem so there could be other wrong hypothesis that i am doing.

Anyway what do you think about applicontion controller for this purpose is it wrong? Is there any other better system or suggested from PRISM team?
I can't find nothing about this problems in PRISM quick start.

Nov 3, 2010 at 6:57 PM


There is not guidance on this topic in Prism out-of-the-box. But WPF and Silverlight provides two main concepts related to focus. For more information on this topic you could take a look at the following documentation sections and Blog Post:

Regarding to create "something that can live crosswise respect regions...": In my opinion you could use Event Aggregator and when the active element changes, it can notifies all modules. For more information about EventAggregation, you could check the following documentation section on MSDN:

Hope this helps.

Fernando Antivero