davjs
Topic Author
Posts: 3
Joined: 07 Sep 2020, 14:45

Recommended way of conditionally rendering complex markup (loadComponent is slow!)

21 Mar 2021, 14:56

It's a common requirement to hide/show certain UI elements based on some state.

For many things, it can be enough to simply bind the visibility of an element.
However for more complex views... we would like to completely destroy/recreate the elements. This way the constructor and destructor of the view (UserControl) is invoked correctly and all listeners etc are properly removed when the view is not displayed.

------------------------------------------------------------------------------------------------------------------------

We tried implementing a ConditionalControl that changed control template depending on a condition. (inspired by https://stackoverflow.com/questions/487 ... l-xaml-wpf)
	
<ConditionalControl Condition="{binding ShowAssetBrowser}">
	<ConditionalControl.TrueTemplate>
		<DataTemplate>
			<AssetBrowser/>
		</DataTemplate>
	</ConditionalControl.TrueTemplate>
</ConditionalControl>
This works and correctly invokes constructor+destructor of the AssetBrowser UserControl. However it is very slow (around 20-40ms). Changing the value of ShowAssetBrowser every second frame drops the framerate to 4-8ps.

The culprit seems to be the LoadComponent call we make in the constructor of the UserControl
class AssetBrowser : public Noesis::UserControl {
....
	AssetBrowser()
	{
		Noesis::GUI::LoadComponent(this, "AssetBrowser.xaml");
	}
....
Is this function parsing xaml?

We tried invoking
Noesis::GUI::LoadXaml(filename);
on all files at startup and then removing the loadComponent call, but the asset browser doesn't show up unless we invoke loadComponent in the constructor.

------------------------------------------------------------------------------------------------------------------------

Questions:
  • What exactly is LoadComponent doing and can we frontload some of the work to only be made once on startup?
  • Or, is there another recommended way of properly destroying components without having to reload the xaml every time?

Tags:
 
User avatar
jsantos
Site Admin
Posts: 3059
Joined: 20 Jan 2012, 17:18
Contact:

Re: Recommended way of conditionally rendering complex markup (loadComponent is slow!)

24 Mar 2021, 01:49

  • What exactly is LoadComponent doing and can we frontload some of the work to only be made once on startup?
As you discovered, LoadComponent is parsing the xaml. That explains the milliseconds you are getting. There is already a ticket (#1301) for fixing this.
  • Or, is there another recommended way of properly destroying components without having to reload the xaml every time?
This depends on what you are trying to achieve, if you could share a bit more about your scenario we will try to provide a workaround.

Who is online

Users browsing this forum: No registered users and 2 guests