英文:
Mudblazor Select Element hidden is not working
问题
我一直在尝试在某些情况下隐藏一个 MudSelect 元素。
然而,看起来即使参数是有效的,MudSelect 也无法被隐藏。
英文:
I've been trying to hide a MudSelect element under some circonstances.
However it looks like a MudSelect can't be hidden even if the parameter is valide.
@page "/"
<MudSelect T="string" hidden="@IsShow">
<MudSelectItem T="string">A<MudSelectItem>
<MudSelectItem T="string">B<MudSelectItem>
</MudSelect>
<button @onclick="@Show">Show/Hide</button>
@code {
private bool IsShow {get;set;} = false;
private void Show()
{
IsShow = !IsShow;
}
}
答案1
得分: 1
你可以选择以下方式之一:
- 使用 visibility CSS 实用类。
- 使用
Disabled
属性 来禁用/启用组件。
<MudSelect Disabled="_disabled" Class="@(_visible ? "visible" : "invisible")" T="string">
<MudSelectItem T="string" Value="@("Cappuccino")" />
<MudSelectItem T="string" Value="@("Cafe Latte")" />
<MudSelectItem T="string" Value="@("Espresso")" />
</MudSelect>
<MudButton OnClick="HandleVisibilityClick">Visible/Invisible</MudButton>
<MudButton OnClick="HandleDisableClick">Disable/Enable</MudButton>
@code {
bool _disabled = false;
bool _visible = true;
void HandleVisibilityClick()
{
_visible = !_visible;
}
void HandleDisableClick()
{
_disabled = !_disabled;
}
}
英文:
You can either:-
- Use the visibility CSS utility class.
- Disable/Enable the component using the
Disabled
property.
<MudSelect Disabled="_disabled" Class="@(_visible?"visible":"invisible")" T="string">
<MudSelectItem T="string" Value="@("Cappuccino")" />
<MudSelectItem T="string" Value="@("Cafe Latte")" />
<MudSelectItem T="string" Value="@("Espresso")" />
</MudSelect>
<MudButton OnClick="HandleVisibilityClick">Visible/Invisible</MudButton>
<MudButton OnClick="HandleDisableClick">Disable/Enable</MudButton>
@code {
bool _disabled = false;
bool _visible = true;
void HandleVisibilityClick()
{
_visible = !_visible;
}
void HandleDisableClick()
{
_disabled=!_disabled;
}
}
答案2
得分: 0
看起来 mudblazor 元素存在 bug。或者这可能是一个特性。
无论哪种情况,您可以通过将它放入一个 div 中并隐藏 div 本身来隐藏该元素。
英文:
Looks like the mudblazor element is bugged. Or this might be a feature.
In eather case, you can hide the element by putting it in a div and hidding the div itself.
@page "/"
<div hidden="@IsShow">
<MudSelect T="string">
<MudSelectItem T="string">A<MudSelectItem>
<MudSelectItem T="string">B<MudSelectItem>
</MudSelect>
</div>
<button @onclick="@Show">Show/Hide</button>
@code {
private bool IsShow {get;set;} = false;
private void Show()
{
IsShow = !IsShow;
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论