none
Problem with GetView in Region (Prism 5.0) RRS feed

  • Question

  • In Module A:

    public void Initialize()
            {
                this.RegionManager.RegisterViewWithRegion("MainRegion",typeof(uc_LogIn));
                this.RegionManager.RegisterViewWithRegion("NavigatorRegion", typeof(uc_LogInNavigate));
                
                if (Application.Current.Resources.Contains("MainContainer"))
                    Application.Current.Resources["MainContainer"] = this.Container;
                else
                    Application.Current.Resources.Add("MainContainer", this.Container);
                if (Application.Current.Resources.Contains("MainRegionManager"))
                    Application.Current.Resources["MainRegionManager"] = this.RegionManager;
                else
                    Application.Current.Resources.Add("MainRegionManager", this.RegionManager);
            }

    In a function in Module B:

    private void OnLogout()
            {
                RegionManager regionManager = (RegionManager)Application.Current.Resources["MainRegionManager"];
                var view = regionManager.Regions["MainRegion"].GetView("uc_LogIn");
            }

    "view" return null. So, How can i get a view in RegionManager without ViewName.

    OR

    How can i set ViewName in RegisterViewWithRegion function ?

    • Moved by Bob Ding Monday, December 25, 2017 5:57 AM
    Friday, December 1, 2017 2:18 AM

All replies

  • Yep, PRISM is very complicated with loads of bells and whistles. But you will still find it frustratingly difficult to do some things look like they ought to be easy. 

    I don't know what stage you are with all this or whether you even have the choice.

    Maybe it's worth mentioning that just a contentcontrol is way simpler than PRISM regions and often can do all you need.

    I've worked on a number of projects where we used PRISM composition only to realise it was mostly just making  things much harder than we needed them to be.

    .

    You can reference the active views of a region:

    var view = region.ActiveViews.FirstOrDefault()

    Then check the type and or cast it.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Friday, December 1, 2017 9:56 AM
  • Hi,

    For patterns & practices: Prism questions, there is a better place to ask Prism related questions : The Discussions for patterns & practices: Prism.

    Sincerely,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 14, 2017 2:46 AM