Domanda

I am trying to navigate to the same view (same as the active one), but with new parameters. The problem is that I struggle to find a clean way to get a currently active view's name from RegionManager

È stato utile?

Soluzione

From my understanding, I would recommend implementing an interface on each of your Views that provides the necessary information to determine which view it is, then use the ActiveViews property of the IRegion to access the active views.

Something like:

//Interface for identifying the Views
public interface IApplicationView
{
    string ViewName { get; }
}

//Example of a View with logic to determine which instance of the View it is
public class ApplicationView : UserControl, IApplicationView
{
    public string ViewName 
    { 
        get { return this.isViewA ? return "ViewA" : return "ViewB"; } 
    }
}

//Example of determining which view
public class OtherComponent
{
    public string GetActiveViewName(IRegion region)
    {
        IApplicationView activeView = region.ActiveViews.FirstOrDefault() as IApplicationView;
        return activeView == null ? string.Empty : activeView.ViewName;
    }
}

Altri suggerimenti

I'm not sure if this method is implemented in Prism 4. But in Prism 6, you can get the name of the active view using the NavigationService Journal.

For example:

string name = RegionManager.Regions["MainRegion"].NavigationService.Journal.CurrentEntry.Uri;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top