Does blazor have the equivalent of webform skins?

Viewed 16

I use a component all over the place in a blazor app. Each instance I set the attributes in markup the same way. Does blazor have an approach to skins, kind of like how webforms does? so I can either create a default skin for a particular component or reference a specific one?

1 Answers

It depends on the component library you are using. For example for Havit.Blazor, you can use the Settings parameter of each component and assign a preconfigured set of parameters to the component. Your code might look like this then:

<HxButton Settings="AppButtonSettings.MainButton" Text="Open" />
<HxButton Settings="AppButtonSettings.SecondaryButton" Text="Fullscreen" />
<HxButton Settings="AppButtonSettings.CloseButton" />

With a backing code with the settings:

public class AppButtonSettings
{
    public static ButtonSettings MainButton { get; } = new()
    {
        Color = ThemeColor.Primary,
        Icon = BootstrapIcon.Fullscreen
    };

    public static ButtonSettings SecondaryButton { get; } = new()
    {
        Color = ThemeColor.Secondary,
        Outline = true
    };

    public static ButtonSettings CloseButton { get; } = new()
    {
        Color = ThemeColor.Danger,
        Outline = true,
        Icon = BootstrapIcon.XLg
    };
}

For more details see https://havit.blazor.eu/concepts/defaults-and-settings

Related