我希望能够隐藏默认标记为删除的行项目,然后在启用切换开关时将它们显示为红色。所以在我的组件上我附加了一个开关:
<MudSwitch @bind-Checked="@blnShowDeleted" Color="Color.Warning">Show deleted</MudSwitch>
@Nadav Hury 的回答告诉我有关RowStyleFunc的信息,这使我找到了 MudBlazor 文档和RowClassFunc,我认为这可能是一个更好的选择。所以我更改了表声明的代码:
<MudTable Items="objVmCustomers" RowClassFunc="ShowDeleted">
我在代码隐藏的 razor.cs 类中创建了一个ShowDeleted方法:
public string ShowDeleted(VmCustomer objVmCustomer, int index)
{
if(objVmCustomer.dtDeleted != null)
{
if (blnShowDeleted == true)
{
return "show-deleted";
}
return "hide-deleted";
}
return "";
}
然后我创建了两个 CSS 类来适应上面的代码:
.show-deleted td { --mud-palette-text-primary: red; }
.hide-deleted { display: none; visibility: collapse; }
这里有个问题:你不能只用color:red; 在show-deleted声明中,因为 CSS 变量--mud-palette-text-primary将覆盖它。您必须覆盖 CSS 变量(我通过检查元素发现了这一点)。
通过使用对一行中的所有 TD 元素进行操作的 CSS 类,这克服了@T0bi 在使用多个样式属性时抱怨的“肮脏”。