SwitchPresenter Lazy Loading By Type #163
michael-hawker
started this conversation in
Ideas
Replies: 2 comments 4 replies
-
I really like this idea, this would allow for easier implementation of app navigation for example. While I don't think this will likely be a need, maybe allowing to also call a generator function (e.g. for setting up stuff before creating the control) would be also an option? |
Beta Was this translation helpful? Give feedback.
2 replies
-
Wondering how much of this would still be needed with the improvements in #550. Think there's still some need here, but maybe it can be a separate control now that just re-uses the same infrastructure? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently
SwitchPresenter
is great for a lot of small cases on frequently changing UI states (toggles, validation, etc...)However, sometimes you want to load Pages or other heavier content for infrequent changes (signed-in vs. not-signed-in). If a user never signs in, why load the page instance and store it? (Even if it's not fully loaded into the VisualTree.)
Or you have an enum with various states, but only 1 or 2 of X may be valid for most cases.
In these cases, you may want to instead instantiate the content when it is needed instead of ahead of time. This can be hard to define in XAML directly with a
SwitchPresenter
, but can easily be encapsulated by another Page or Control.What if instead of just taking XAML content directly, the
SwitchPresenter
could take a type instead?In the
SignedIn
case, theSwitchPresenter
instead of setting theContent
to our presenter in its logic here:Windows/components/Primitives/src/SwitchPresenter/SwitchPresenter.cs
Lines 165 to 170 in 710c30f
Would detect that the
ContentType
property is set on the case and instantiate whatever that type is (UserControl, Page, etc...) and set it as the content, similar to frame navigation.This way if the user never signs in, nothing else is ever loaded, we're just holding a reference to a
Type
as part of theCase
definition.Not sure if it makes sense to have another property on the
SwitchPresenter
or eachCase
to allow for caching the instantiated control so only ever one instance is created?Anyway, seemed like an interesting extension/hybrid scenario that looks fairly straight-forward to add-on to the
SwitchPresenter
control.Beta Was this translation helpful? Give feedback.
All reactions