WPF page in separate assembly constructed always!

Oct 29, 2011 at 2:45 PM

Hello All!

A have a WPF App + one class library. In both I have visual pages.

I'm using frame to navigate through the pages with de following code:

        private void LoadPage_Click(object sender, RoutedEventArgs e)
        {
            string pageName;
            string page;

            page = ((FrameworkElement)sender).Name.Substring(3);

            pageName = "Views/" + page + ".xaml";

                // If is new call 
                if (frmNavigate.Resources[pageName] == null)

                    frmNavigate.Navigate(new Uri(pageName, UriKind.Relative));

                // If page is old
                else
                    frmNavigate.Navigate(frmNavigate.Resources[pageName]);

        }

And...

      private void frmNavigate_LoadCompleted(object sender, NavigationEventArgs e)
        {
            if (e.Uri != null)
            {
                if (frmNavigate.Resources[e.Uri.ToString()] == null)
                    frmNavigate.Resources.Add(e.Uri.ToString(), e.Content);
            }
        }

I need that pages are created only once, so I test whether the page has not been loaded (if (frmNavigate.Resources[pageName] == null)). 

The code works well with the pages contained in App, in other words, pages are create only once. But, with the pages contained in class libaray, every time I call the pages are created!

Why this happens?

Alexandre