SelectedValuesChanged 与 @bind-SelectedValues

SelectedValuesChanged with @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”,但它说该参数已被 bind-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
}