Bui Quang Huy Bui Quang Huy - 1 year ago 42
C# Question

Initialize XAML page once when application is running UWP

I want to init XAML and its code behind page once when that page is open. I try to register it with

but it still initializes every time I navigate to it. So do we have any way to keep it alive during the application lifetime?


I registered my XAML file and code behind with
like this:

Container.RegisterType<MyPage>(new ContainerControlledLifetimeManager());

But it still run the constructor every time we navigate to that page.
In ContainerControlledLifetimeManager comment say:

A Microsoft.Practices.Unity.LifetimeManager that holds onto the
instance given to it. When the
Microsoft.Practices.Unity.ContainerControlledLifetimeManager is
disposed, the instance is disposed with it.

Answer Source

How about setting NavigationCacheMode of your page to either Required or Enabled instead?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download