SelectedValues与@bind SelectedValues一起更改



有可能做到吗?我目前正试图在MudBlazor中选择某个内容时弹出一个显示。但当我尝试调用函数时,使用选定的值,它永远不会命中它。enter code here

<MudSelect T="string" MultiSelection="true" SelectAll="true" SelectAllText="Select all InputModules" HelperText="@value" @bind-Value="value" @bind-SelectedValues="SelectedInputModules" MultiSelectionTextFunc="@(new Func<List<string>, string>(GetMultiSelectionText))" Label="InputModules" AdornmentIcon="@Icons.Material.Filled.Search">
@foreach (var con in conTask.Select(x => x.InputModuleName).Distinct())
{
<MudSelectItem T="string" Value="@con" OnClick="@(()=> ToggleInputModuleVisibility(SelectedInputModules.ToString()))">@con</MudSelectItem>
}
@code 
{    private string value { get; set; } = "Nothing selected";
private IEnumerable<string> SelectedInputModules { get; set; } = new HashSet<string>();
private string GetMultiSelectionText(List<string> selectedValues)
{
return $"{selectedValues.Count} InputModule{(selectedValues.Count > 1 ? "s have" : " has")} been selected";
}

}

我不太清楚是逻辑错误。还是使用不同的方法来解决问题;SelectedValuesChanged;但它表示该参数已被绑定SelectedValues 使用

删除@bind SelectedValues="SelectedInputModules";并使用SelectedValuesChanged=";OnSelectedValuesChanged":

<MudSelect T="string" MultiSelection="true" SelectAll="true" SelectAllText="Select all InputModules"
HelperText="@value" @bind-Value="value"
MultiSelectionTextFunc="@(new Func<List<string>, string>(GetMultiSelectionText))" Label="InputModules"
AdornmentIcon="@Icons.Material.Filled.Search" SelectedValuesChanged="OnSelectedValuesChanged">
@foreach (var con in conTask.Select(x => x.InputModuleName).Distinct())
{
<MudSelectItem T="string" Value="@con"> @con </MudSelectItem>
}

然后在OnSelectedValuesChanged方法中手动绑定SelectedInputModules:

private void OnSelectedValuesChanged(IEnumerable<string> values)
{
SelectedInputModules = values;
// Show your popup
}

相关内容

  • 没有找到相关文章

最新更新