Cannot find child name in Grid.
I'm currently working on a navigation system. When a view is told be be shown, the navigation first looks if a control of that name already exists. If not, it creates the element, gives it a name, and adds it to the children of the root. If it does exist, it will simply enable and show that instead of creating a new one.
The problem is that I cannot find any children I've added.
I cannot seem to find an object of that name. If I create the view in XAML and give it an x:Name attribute, FindName does work. Furthermore, when I look up all children, it says the source is null.
https://i.imgur.com/K7zTRjp.png
The problem is that I cannot find any children I've added.
Code: Select all
control.Name = "Name";
Root.Children.Add(control);
Root.FindName("Name");
Code: Select all
IEnumerable<object> c = Root.Children.OfType<object>();
Last edited by asusralis on 02 Dec 2018, 02:03, edited 1 time in total.
-
sfernandez
Site Admin
- Posts: 3008
- Joined:
Re: Cannot find child name in Grid.
To programatically register objects by name in the UI tree you have to call RegisterName().
That is what XAML parser does when it finds the x:Name attribute in a node.
That is what XAML parser does when it finds the x:Name attribute in a node.
Code: Select all
Root.RegisterName("Name", control);
Root.Children.Add(control);
Control control = (Control)Root.FindName("Name");
Who is online
Users browsing this forum: Semrush [Bot] and 7 guests