Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic UIElement.FindName #2652

Open
TranquilAbyss opened this issue Feb 23, 2025 · 0 comments
Open

Generic UIElement.FindName #2652

TranquilAbyss opened this issue Feb 23, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@TranquilAbyss
Copy link
Contributor

TranquilAbyss commented Feb 23, 2025

Is your feature request related to a problem? Please describe.
I would prefer a generic method than casting inline so I created a custom UIElementExtension class to do that. I Thought it could be added to Stride as well. This is simply a nice to have feature to match InstantiateElement<T>. When using UILibraries .

The use case is I am always trying to get named subcomponents of the UIElements when setting up UI behavior in code, and it would be nice if I could get the function to retrieve the type of UI element I am trying to find rather than casting it in the setup game logic.

Describe the solution you'd like
Implement this function into UIElement

public T FindName<T>(string name) where T: UIElement
{
    return (T)FindName(name);
}

Describe alternatives you've considered
I am currently using

using Stride.UI;

public static class UIElementExtension
{
    public static T FindName<T>(this UIElement uiElement, string name) where T: UIElement
    {
        return (T)uiElement.FindName(name);
    }
}
@TranquilAbyss TranquilAbyss added the enhancement New feature or request label Feb 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant