|
1 | 1 |
|
2 | 2 | <MudGrid> |
3 | 3 | <MudItem xs="12" sm="8"> |
4 | | - <MudSelectExtended MultiSelectionTextFunc="@(_radioGroup?.SelectedOption == 1 ? new Func<List<string>, string>(GetMultiSelectionText) : null)" MultiSelection="true" ValuePresenter="_valuePresenter" @bind-Value="value" @bind-SelectedValues="options" T="string" Label="US States" AnchorOrigin="Origin.BottomCenter" |
| 4 | + <MudSelectExtended MultiSelectionTextFunc="@(_radioGroup?.SelectedOption == 1 ? new Func<List<int?>, string>(GetMultiSelectionText) : null)" MultiSelection="true" ValuePresenter="_valuePresenter" T="int?" @bind-Value="intValue" @bind-SelectedValues="intValues" Label="Complex Type" AnchorOrigin="Origin.BottomCenter" |
| 5 | + ChipCloseable="_chipCloseable" ChipSize="_chipSize" ChipVariant="_chipVariant"> |
| 6 | + @foreach (var item in complexes) |
| 7 | + { |
| 8 | + <MudSelectItemExtended T="int?" Value="@item.Value" Text="@item.Text" /> |
| 9 | + } |
| 10 | + </MudSelectExtended> |
| 11 | + |
| 12 | + <MudSelectExtended MultiSelectionTextFunc="@(_radioGroup?.SelectedOption == 1 ? new Func<List<string>, string>(GetMultiSelectionText2) : null)" MultiSelection="true" ValuePresenter="_valuePresenter" @bind-Value="stringValue" @bind-SelectedValues="stringValues" T="string" Label="US States" AnchorOrigin="Origin.BottomCenter" |
5 | 13 | ChipCloseable="_chipCloseable" ChipSize="_chipSize" ChipVariant="_chipVariant"> |
6 | 14 | @foreach (var state in states) |
7 | 15 | { |
|
20 | 28 | <MudItem xs="6"> |
21 | 29 | <MudText Typo="Typo.subtitle2">Value:</MudText> |
22 | 30 | <MudText Typo="Typo.subtitle2">"</MudText> |
23 | | - <MudText Typo="Typo.body2" Class="pl-4">@value</MudText> |
| 31 | + <MudText Typo="Typo.body2" Class="pl-4">@stringValue</MudText> |
24 | 32 | <MudText Typo="Typo.subtitle2">"</MudText> |
25 | 33 | </MudItem> |
26 | 34 | <MudItem xs="6"> |
27 | 35 | <MudText Typo="Typo.subtitle2">SelectedValues: HashSet<string></MudText> |
28 | 36 | <MudText Typo="Typo.subtitle2">{</MudText> |
29 | | - <MudText Typo="Typo.body2" Class="pl-4">@(string.Join(", ", options.Select(x => $"\"{x}\"")))</MudText> |
| 37 | + <MudText Typo="Typo.body2" Class="pl-4">@(string.Join(", ", stringValues.Select(x => $"\"{x}\"")))</MudText> |
30 | 38 | <MudText Typo="Typo.subtitle2">}</MudText> |
31 | 39 | </MudItem> |
32 | 40 | </MudGrid> |
|
39 | 47 | @code { |
40 | 48 | MudRadioGroup<int> _radioGroup; |
41 | 49 | ValuePresenter _valuePresenter = ValuePresenter.Text; |
42 | | - string value { get; set; } = "Nothing selected"; |
43 | | - IEnumerable<string> options { get; set; } = new HashSet<string>() { "Alaska", "California" }; |
| 50 | + string stringValue { get; set; } = "Nothing selected"; |
| 51 | + IEnumerable<string> stringValues { get; set; } = new HashSet<string>() { "Alaska", "California" }; |
| 52 | + int? intValue; |
| 53 | + IEnumerable<int?> intValues { get; set; } = new HashSet<int?>() { 2, 3 }; |
44 | 54 | bool _chipCloseable = false; |
45 | 55 | Variant _chipVariant = Variant.Filled; |
46 | 56 | Size _chipSize = Size.Small; |
47 | 57 |
|
| 58 | + public class Complex |
| 59 | + { |
| 60 | + public int? Value { get; set; } |
| 61 | + public string Text { get; set; } |
| 62 | + } |
| 63 | + |
| 64 | + private Complex[] complexes = |
| 65 | + { |
| 66 | + new Complex() { Value = null, Text = "Null" }, |
| 67 | + new Complex() { Value = 1, Text = "A"}, |
| 68 | + new Complex() { Value = 2, Text = "B"}, |
| 69 | + new Complex() { Value = 3, Text = "C"}, |
| 70 | + new Complex() { Value = 4, Text = "D"}, |
| 71 | + new Complex() { Value = 5, Text = "E"}, |
| 72 | + }; |
| 73 | + |
48 | 74 | private string[] states = |
49 | 75 | { |
50 | 76 | "Alabama", "Alaska", "American Samoa", "Arizona", |
|
63 | 89 | "Washington", "West Virginia", "Wisconsin", "Wyoming", |
64 | 90 | }; |
65 | 91 |
|
66 | | - private string GetMultiSelectionText(List<string> selectedValues) |
| 92 | + private string GetMultiSelectionText(List<int?> selectedValues) |
| 93 | + { |
| 94 | + return $"{selectedValues?.Count} value{(selectedValues?.Count > 1 ? "s have" : " has")} been selected"; |
| 95 | + } |
| 96 | + |
| 97 | + private string GetMultiSelectionText2(List<string> selectedValues) |
67 | 98 | { |
68 | 99 | return $"{selectedValues.Count} state{(selectedValues.Count > 1 ? "s have" : " has")} been selected"; |
69 | 100 | } |
|
0 commit comments