MudBlazor 上的多选不更新文本字段

问题描述 投票:0回答:1

我正在将 MudBlazor 用于 Blazor 项目。我正在尝试使用枚举创建多选组件。我让它工作,以便组件显示并正确选择选择。问题出在组件的实际显示上。首先,即使没有选择任何内容,也会显示第一个条目的文本,该文本与给定组件的标签重叠。其次,一旦我选择了不同的组件,即使我设置了 MultiSelectionTextFunc,文本也不会更新,并且在调试时,我看到被调用的函数正在生成正确的文本。这是演示的链接:https://try.mudbazor.com/snippet/GOwIYdloqAKBdPcl

我只是想弄清楚如何解决重叠文本以及为什么我的文本没有更新。

blazor mudblazor
1个回答
0
投票

您必须使用

T="Color?"
而不是
T="Color"
:

@using Try.UserComponents

<MudSelect T="Color?" Label="Choose a color" MultiSelection="true" SelectAll="true" SelectAllText="Select All" @bind-SelectedValues="SelectedColors" AdornmentIcon="@Icons.Material.Filled.Search" AnchorOrigin="Origin.BottomCenter">
    <MudSelectItem T="Color?" Value="Color.Red">Red</MudSelectItem>
    <MudSelectItem T="Color?" Value="Color.Blue">Blue</MudSelectItem>
    <MudSelectItem T="Color?" Value="Color.LightBlue">Light Blue</MudSelectItem>
</MudSelect>

@code {
    private IEnumerable<Color?> SelectedColors { get; set; } = new HashSet<Color?>();
}

https://try.mudblazor.com/snippet/mYGSkxlyKBgQuJlK

© www.soinside.com 2019 - 2024. All rights reserved.