Recommended way of conditionally rendering complex markup (loadComponent is slow!)
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)
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
Is this function parsing xaml?
We tried invoking 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:
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)
Code: Select all
<ConditionalControl Condition="{binding ShowAssetBrowser}">
<ConditionalControl.TrueTemplate>
<DataTemplate>
<AssetBrowser/>
</DataTemplate>
</ConditionalControl.TrueTemplate>
</ConditionalControl>
The culprit seems to be the LoadComponent call we make in the constructor of the UserControl
Code: Select all
class AssetBrowser : public Noesis::UserControl {
....
AssetBrowser()
{
Noesis::GUI::LoadComponent(this, "AssetBrowser.xaml");
}
....
We tried invoking
Code: Select all
Noesis::GUI::LoadXaml(filename);
------------------------------------------------------------------------------------------------------------------------
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?
Re: Recommended way of conditionally rendering complex markup (loadComponent is slow!)
As you discovered, LoadComponent is parsing the xaml. That explains the milliseconds you are getting. There is already a ticket (#1301) for fixing this.
- What exactly is LoadComponent doing and can we frontload some of the work to only be made once on startup?
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.
- Or, is there another recommended way of properly destroying components without having to reload the xaml every time?
Who is online
Users browsing this forum: No registered users and 3 guests