Right way to delete codebehind element (Grid) and problem with FindName("grid")
Posted: 29 Mar 2018, 11:03
I load xaml file which contain other gui elements in to MainWindow grid somewhere. This is working OK.
If I understand this code give me this result?
But I have problem find and delete it. This is not working:
But when I load xaml file in to member object, then I can delete it with this:
It is right?
Question is, why I can not findName grid created in codebehind?
Code: Select all
void noesis_IView_Windows::mf_AddWindow_toGridView(const std::string &pathToXaml)
{
Noesis::Ptr<Noesis::FrameworkElement> fe = Noesis::GUI::LoadXaml<Noesis::FrameworkElement>(pathToXaml.c_str());
Noesis::Grid * g = fe->FindName<Noesis::Grid>("grid_options_view");
m_NsIViewDelegate->GetContent()->FindName<Noesis::Grid>("grid_sidebar_view")->GetChildren()->Add(g);
}Code: Select all
<Grid x:Name="grid_sidebar_view" >
<Grid x:Name="grid_options_view" > <!-- grid_options_view iis loaded from xaml file with all his content -->
</Grid >
</Grid>Code: Select all
Noesis::Grid * grid_sidebar_view = m_NsIViewDelegate->GetContent()->FindName<Noesis::Grid>("grid_sidebar_view");
Noesis::Grid * g = grid_sidebar_view->FindName<Noesis::Grid>(gridName.c_str()); // find nothing g will be empty
if (g != nullptr)
{
grid_sidebar_view ->GetChildren()->Remove(g); // never happens because g is empty.
}
Code: Select all
Noesis::Ptr<Noesis::FrameworkElement> fe = Noesis::GUI::LoadXaml<Noesis::FrameworkElement>(pathToXaml.c_str());
m_NsGrid_d = fe->FindName<Noesis::Grid>("grid_options_view"); // m_NsGrid_d is member Noesis::Grid * m_NsGrid_d;
// deletion
Noesis::Grid * grid_sidebar_view = m_NsIViewDelegate->GetContent()->FindName<Noesis::Grid>("grid_sidebar_view");
grid_sidebar_view->GetChildren()->Remove(m_NsGrid_d); // only this way I can delete this grid (it dissapear from GUI)Question is, why I can not findName grid created in codebehind?