Search code examples
user-controlscontrolswinui-3

Is possible to have a different tag name in winui 3 user control?


Is it possible to have a different tag name fo my user control?

My class looks like:

public sealed partial class ValidationControl : UserControl { ... }

and used like this:

<controls:ValidationControl Model="{x:Bind ViewModel, Mode=OneWay}" PropertyName="Name"/>

Is there some property in my user control that could change the tag name but that my class' name will continue naming ValidationControl?:

<controls:Validation Model="{x:Bind ViewModel, Mode=OneWay}" PropertyName="Name"/>

I have another class named Validation, that's why I cannot name only Validation to my control.


Solution

  • You could create a one-liner marker type:

    public class AlternativeName : ValidationControl { }
    

    ...and instantiate this one instead of the base class:

    <controls:lternativeName ...
    

    Don't forget to also remove the sealed keyword from the definition of the existing ValidationControl class:

    public partial class ValidationControl : UserControl { ... }