CssClassAttribute 特性

为组件类或参数定义 CssClassAttribute 特性

组件

css class 字符串总是在组件初始化时应用。

Alert.razor
@inherits BlazorComponentBase

<div @attributes="AdditionalAttributes">
    @ChildContent
</div>

@code{
    [CssClass("alert")]
    public Alert()
    {
    }
    
    [Parameter]public RenderFragment? ChildContent { get; set; }
}
[CssClass("alert")]
public class Alert : BlazorComponentBase, IHasChildContent
{
    [Parameter]public RenderFragment? ChildContent { get; set; }
}

参数

当参数有值时,才可以应用 CSS 值

  • bool 类型

只有为 true 时才应用 CSS

  • Enum 类型

参数的值会被添加到带有枚举成员的css字符串后面

  • 其他值类型

参数的值会追加到 css 值得后面

注意:该值应该为 Nullable,因为 int 类型的默认值为0

尽管你没有为参数赋值,但是依然会有默认值

预定义

为接口进行预定义并进行复用

  • 覆盖预定义

排序

设置 Order 可以为生成的 CSS 排序

禁用

设置 Disbaled=true 可以禁用 CSS 的附加操作

连接

设置 Concat=true 可以连接父类定义的 CssClassAttribute 的值

Last updated