【发布时间】:2021-01-06 21:44:12
【问题描述】:
如果某个条件为假,我正在尝试制作一个禁用的按钮。对于常规按钮,这是可行的:
<button @disabled="!IsReady">Click me</button>
@code
{
public bool IsReady { get; set; }
}
我正在使用具有 MatButton 版本的 button 的 MatBlazor 库:
<MatButton Disabled="@!IsReady">Click me</MatButton>
后者不起作用:它给出以下错误:
组件属性不支持复杂内容(混合 C# 和标记)
在好的 ol' WPF 中,我们可能会在绑定中使用转换器,因此绑定的布尔值是反转的。这是 MatBlazor 的限制吗?
我看到的快速解决方案是执行以下操作:
<MatButton Disabled="@IsNotReady">Click me</MatButton>
@code
{
public bool IsReady { get; set; }
public bool IsNotReady => !IsReady;
}
有没有更好的办法?
【问题讨论】: