Forcing a XAML to load via a throw away renderer
Hello,
So I am attempting to load a xaml dynamically with the following line:
However when I try to find the children or access any nodes under this element, I get a value of 0.
Once I add this to my main GUI tree like this:
and then call Noesis_Update I am able to traverse the new xaml tree. Now this works fine, but it will increase the complexity of my code since I make the update and children add calls at the top of my frame. To reduce this complexity a tried using a throw away renderer as follows based on (http://www.noesisengine.com/docs/Gui.Core.SDKGuide.html):
This worked well and prevents me from restructuring my code, so my question is this...Is this a safe way to force a XAML to load? I am assuming that the renderer resources will be deallocated after it goes out of scope, but the loaded XAML elements are still being kept in memory (which is what I need). Really, all I need is some form of commit call to force a complete loading of the XAML, is there a better way to do this?
So I am attempting to load a xaml dynamically with the following line:
Code: Select all
user_control_ = Noesis::Gui::LoadXaml<Noesis::Gui::FrameworkElement>(xaml_filename.c_str());
Code: Select all
NsSize numChildren = VisualTreeHelper::GetChildrenCount(user_control_);
Code: Select all
panel->GetChildren()->Add((Noesis::Gui::FrameworkElement*) root.GetPtr());
Code: Select all
Ptr<IRenderer> xamlRenderer = CreateRenderer(user_control_.GetPtr());
-
sfernandez
Site Admin
- Posts: 3188
- Joined:
Re: Forcing a XAML to load via a throw away renderer
Hi,
If you want to look for a specific element in a xaml it is better to assign a Name to it and use FindName to obtain a reference.
If you need that the Visual Tree of your loaded xaml is totally generated, you have to add it to the panel or container, because the styles and templates used to generate that visual tree depend on the place you attach your xaml.
Once attached you can use the UpdateLayout() function to ensure that everything gets generated and correctly measured for render:
Using a temporary renderer sometimes won't be a solution because the visual elements generated will be destroyed and regenerated again when connected to the main Renderer and final templates are assigned.
If you want to look for a specific element in a xaml it is better to assign a Name to it and use FindName to obtain a reference.
Code: Select all
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Button x:Name="okBtn" Content="OK"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Margin="10"/>
</Grid>
Code: Select all
Ptr<FrameworkElement> root = LoadXaml<FrameworkElement>(filename.c_str());
Button* okBtn = root->FindName<Button>("okBtn");
//...
Once attached you can use the UpdateLayout() function to ensure that everything gets generated and correctly measured for render:
Code: Select all
Ptr<FrameworkElement> root = LoadXaml<FrameworkElement>(filename.c_str());
//...
panel->GetChildren()->Add(root.GetPtr());
panel->UpdateLayout();
Re: Forcing a XAML to load via a throw away renderer
Thanks for the info, but it looks like UpdateLayout is not exposed to me. I must be on an older version.
-
sfernandez
Site Admin
- Posts: 3188
- Joined:
Re: Forcing a XAML to load via a throw away renderer
UpdateLayout was added in 1.1.12 version. In previous versions you need to call Measure and Arrange on the panel/container hosting your loaded xaml.
Who is online
Users browsing this forum: Ahrefs [Bot] and 5 guests