Noesis::GUI::LoadXaml, SetContent and FindName not working as expected
I have a MainWindow class derived from Noesis::ContentControl.
I call
I then later call
and it is always nullptr.
The Xaml contains a widget with
What am I doing wrong?
I call
Code: Select all
auto content = Noesis::GUI::LoadXaml(...);
mainwindow->SetContent(content)Code: Select all
mainwindow->FindName("WidgetName")The Xaml contains a widget with
Code: Select all
x:Name="WidgetName".Re: Noesis::GUI::LoadXaml, SetContent and FindName not working as expected
Further to this, nothing seems to have a name:
GetName always returns an empty string. I'm confused, multiple elements in the source XAML have x:Name attributes.
Code: Select all
auto filter = [](Noesis::Visual* target) -> Noesis::HitTestFilterBehavior { return Noesis::HitTestFilterBehavior::HitTestFilterBehavior_Continue; };
auto window = sState.mApplication->GetMainWindow();
Noesis::HitTestResultCallback resultcb = [](const Noesis::HitTestResult& result) -> Noesis::HitTestResultBehavior
{
auto felem = Noesis::DynamicCast<Noesis::FrameworkElement*>(result.visualHit);
if(felem)
{
auto classname = felem->GetClassType()->GetName();
ZU_Info(zu::LoggingSystem::UI) << "FELEM: " << (unsigned long long)felem << felem->GetName() << " " << classname;
}
return Noesis::HitTestResultBehavior::HitTestResultBehavior_Continue;
};
Noesis::Point point = Noesis::VisualTreeHelper::GetRoot(window)->PointFromScreen(Noesis::Point(mousex, mousey));
Noesis::VisualTreeHelper::HitTest(Noesis::VisualTreeHelper::GetRoot(window), point, filter, resultcb);-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Noesis::GUI::LoadXaml, SetContent and FindName not working as expected
Every named element in a xaml will be registered in the xaml's root namescope. In the code you attached this will be the namescope of the 'content' object. So you will be able to find the named elements by doing the FindName on that object:
Code: Select all
auto content = Noesis::GUI::LoadXaml(...);
mainwindow->SetContent(content)
...
content->FindName("WidgetName");
Re: Noesis::GUI::LoadXaml, SetContent and FindName not working as expected
Thankyou, this worked but is very surprising. My mental model of how XAML is used is clearly very wrong.
Re: Noesis::GUI::LoadXaml, SetContent and FindName not working as expected
One of the reasons behind this behavior is for example, UserControls. Instancing a UserControl several times would create name conflicts if the UserControl contains x:Name inside.
Who is online
Users browsing this forum: Bing [Bot] and 6 guests