stride3d / stride

Stride Game Engine (formerly Xenko)
https://stride3d.net
MIT License
6.32k stars 917 forks source link

FindName Mention that it may return the parent object of same name #2325

Open TranquilAbyss opened 2 weeks ago

TranquilAbyss commented 2 weeks ago

Describe the update or improvement you would like to see

I would like to see added to the remarks of UIElement FindName additional text , checking parent first. or something equivalent.

Is this related to a specific part of the documentation? UIElement.cs FindName() line 1086

Why is this update needed? I found the current text misleading to the functionality in the case of the parent and child with the same name. Hopefully this change can help people spend less time next time it is encountered.

I had a button named after its function (ChangeOwner). But then did a refactor and made it part of a Grid called (ChangeOwner). I know I could practice better naming standards, but I thought this was fine due to the summery Finds an element that has the provided identifier name in the element children.. Since Button (ChangeOwner) was a child of Grid (ChangeOwner) I expected it to get the child element from the children of the Grid. When I tried to FindName("ChangeOwner") it returned the parent Grid instead of the Button.

Additional context I am not sure if anyone is using this segment of FindName. I am not recommending removing it for now since it could be a breaking change.

if (Name == name)
    return this;

If its not used I think this code segment could be removed.

Proposed changes If you have a specific change in mind, you can suggest the text or code snippet here. /// <remarks>If several elements with the same name exist return the first found, checking parent first</remarks>