I have a question to creator of WinRT XAML Toolkit that had helped me a lot.
What is the best mechanism for working with rich pages in WinRT?
These are the conditions:
AlternativeFrame.Preload()
method from the Toolkit.That's why I stand before choosing to either constantly preload these pages (create, draw, fill) but when it is needed or creating my own page cache that would store them (maybe I am blind and the Toolkit already has this functionality?).
Can you advise what's the best practice in this problem and whether maybe there's a third way?
To add some more background - the WinRT XAML Toolkit library has two controls: AlternativeFrame
and AlternativePage
that are alternate implementations of the base Frame
and Page
classes that come out of the box in Windows 8 SDK for dealing with UI navigation - similar to how you navigate pages in a web browser. The API of these alternative controls is almost the same as in the base ones, but it adds some more support for asynchronous development model, page transition animations and preloading pages before they are requested.
Currently the Preload()
method preloads a page of a given type in the background and puts it in a cache and when a Navigate()
method is invoked to navigate to the page of that type - instead of instantiating a new page - the one in the cache is used, so it can immediately be shown, but also - the cache gets emptied and the next time you want to navigate to that same page - you need to preload it again. This works well if you don't return to the preloaded page often and the page uses a lot of memory, but if you want to keep that page in cache - there is not built-in support for that. The original Page class has a NavigationCacheMode property that allows to configure a page to be kept in cache once it is loaded the first time and it would be a good option for you, but AlternativePage
doesn't have that support yet. I am thinking about adding it there today since I have some free time, so you might decide to wait for me to do it. Other options include
NavigationCacheMode="Required"
on your Page
so it stays in memory forever, though you do lose the Preload()
feature then.Content
of your page in some sort of cache (e.g. a Dictionary<Type,UIElement>
that maps page type to content) and remove it from the page (set Content to null) when you navigate away from the page and then add it back to the page when you navigate to it and the content is found in the cache. In that case you would probably want to make the Content
be a separate UserControl
and skip calling InitializeComponent()
in the constructor if you retrieve the content from the cache since you can only have one Content
and having it defined in a separate UserControl
will allow you to get auto-generated code that gets executed in InitializeComponent()
that grants you easy access to named elements, registers event handlers etc.