Justin XL
Justin XL

Reputation: 39006

Setting x:DeferLoadStrategy in code behind

In Windows 10, we have a new way of deferring xaml rendering by setting

x:DeferLoadStrategy="Lazy" in xaml.

However, I failed to find any document indicating how to achieve the same thing in code-behind. The reason that I want this is that I need to somehow hide the element completely again (i.e. removing it from the visual tree to boost animation performance) after it's been realised.

Any ideas?

Upvotes: 4

Views: 1349

Answers (1)

Rob Caplan - MSFT
Rob Caplan - MSFT

Reputation: 21899

If you're managing your elements from code-behind you don't need x:DeferLoadStrategy to defer an element being loaded: since you're destroying and creating the element from code you can choose when to destroy (mod garbage collection) and when to create it.

DeferLoadStrategy controls how the items are loaded from markup. It's designed to easily increase load time by delaying the creation of unneeded elements until they are needed rather than to fully control the lifetime of elements as they come and go or to unload elements after they've been realized. This is something that could already be done from code, and DeferLoadStrategy allows it to be done via markup.

Upvotes: 5

Related Questions