Ali Shafai
Ali Shafai

Reputation: 5161

prism switch between views in the same region

I have a region named "ActiveModule" and want to re-use it with different views, for example you press the search button and I show the search view in there, etc. etc.

The only way I can ATM do that is to deactivate all the active views in that region and then activate the view I like, this is a bit dirty, is there a "viewManager" or something similar I can use?

Upvotes: 3

Views: 4741

Answers (5)

WPFKK
WPFKK

Reputation: 1477

Not sure how you laid out your framework but if you are using navigation related framework you can simply call

regionManager.RequestNavigate(RegionNames.MainContentRegion, new Uri("your target view" + parameters, UriKind.Relative));

the above line will take care of deactivating other views in the region.

Otherwise if you do view discovery or view injection you can use the approach here

region.Activate(view);

Upvotes: 0

Sebastian
Sebastian

Reputation: 173

Did you consider to use a type of contentControl that is able to show multiple views? For example you can use a TabControl like this:

<TabControl Name="MainRegion" Regions:RegionManager.RegionName="MainRegion"/>

You can now add more than one view to the region. Use INavigationAware and IActiveAware interfaces from Prism to be able to do navigation on the views (activate them, find the correct view etc.).

Upvotes: 1

ioWint
ioWint

Reputation: 1629

To my knowledge what you are doing is the only way, theoretically in SCSF the top most view was activated by the framework. You could create ur own ViewManager or a ShowViewService equivalent to get this done. MAtter of fact, thats what i have done!

Upvotes: 0

Jordan
Jordan

Reputation: 9911

If you are using a IRegionManager, you can remove all of the views whose types you recognize and then add your own.

    foreach (var view in _regionsManager.Regions["MyRegion"].Views.ToArray())
    {
        if (view is MyType ||
            view is MyOtherType)
            _regionsManager.Regions["MyRegion"].Remove(view);
    }

    _regionsManager.AddToRegion("MyRegion", typeof(MyView));

Its by no means ideal, but it works. :)

Upvotes: 0

Krimson
Krimson

Reputation: 772

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.

Upvotes: 4

Related Questions