File tree Expand file tree Collapse file tree 4 files changed +43
-3
lines changed
CodeBeam.MudExtensions/Components
ComponentViewer.Docs/Pages/Examples Expand file tree Collapse file tree 4 files changed +43
-3
lines changed Original file line number Diff line number Diff line change 2727 <MudVirtualize IsEnabled =" @Virtualize" Items =" GetSearchedItems()" Context =" item" OverscanCount =" @OverscanCount" >
2828 @if (MudSelectExtended != null )
2929 {
30- <MudSelectItemExtended Value =" @item" Text =" @(MudSelectExtended. ToStringFunc == null ? item.ToString() : MudSelectExtended. ToStringFunc(item))" />
30+ <MudSelectItemExtended Value =" @item" Text =" @(ToStringFunc == null ? item.ToString() : ToStringFunc(item))" />
3131 }
3232 else
3333 {
34- <MudListItemExtended Value =" @item" Text =" @item.ToString()" />
34+ <MudListItemExtended Value =" @item" Text =" @(ToStringFunc == null ? item.ToString() : ToStringFunc(item) )" />
3535 }
3636 </MudVirtualize >
3737 }
Original file line number Diff line number Diff line change @@ -107,6 +107,27 @@ public IEqualityComparer<T> Comparer
107107 }
108108 }
109109
110+ private Func < T , string > _toStringFunc = x => x ? . ToString ( ) ;
111+ /// <summary>
112+ /// Defines how values are displayed in the drop-down list
113+ /// </summary>
114+ [ Parameter ]
115+ [ Category ( CategoryTypes . FormComponent . ListBehavior ) ]
116+ public Func < T , string > ToStringFunc
117+ {
118+ get => _toStringFunc ;
119+ set
120+ {
121+ if ( _toStringFunc == value )
122+ return ;
123+ _toStringFunc = value ;
124+ Converter = new DefaultConverter < T >
125+ {
126+ SetFunc = _toStringFunc ?? ( x => x ? . ToString ( ) ) ,
127+ } ;
128+ }
129+ }
130+
110131 /// <summary>
111132 /// Predefined enumerable items. If its not null, creates list items automatically.
112133 /// </summary>
Original file line number Diff line number Diff line change 100100 Clickable =" true" Color =" @Color" Dense =" @Dense" ItemCollection =" @ItemCollection" Virtualize =" @Virtualize" DisablePadding =" @DisablePopoverPadding" DisableSelectedItemStyle =" @DisableSelectedItemStyle"
101101 MultiSelection =" @MultiSelection" MultiSelectionComponent =" @MultiSelectionComponent" MultiSelectionAlign =" @MultiSelectionAlign" SelectAll =" @SelectAll" SelectAllText =" @SelectAllText"
102102 CheckedIcon =" @CheckedIcon" UncheckedIcon =" @UncheckedIcon" IndeterminateIcon =" @IndeterminateIcon" SelectValueOnTab =" @SelectValueOnTab" Comparer =" @Comparer"
103- ItemTemplate =" @ItemTemplate" ItemSelectedTemplate =" @ItemSelectedTemplate" ItemDisabledTemplate =" @ItemDisabledTemplate" SearchBox =" @SearchBox" >
103+ ItemTemplate =" @ItemTemplate" ItemSelectedTemplate =" @ItemSelectedTemplate" ItemDisabledTemplate =" @ItemDisabledTemplate" SearchBox =" @SearchBox" ToStringFunc = " @ToStringFunc " >
104104 @ChildContent
105105 </MudListExtended >
106106 </CascadingValue >
Original file line number Diff line number Diff line change 1212 <MudText Class =" ma-4" >Enum List</MudText >
1313 <MudListExtended T =" Continent" ItemCollection =" (ICollection<Continent>)Enum.GetValues<Continent>()" Clickable =" true" MaxItems =" _maxItems" SearchBox =" _searchBox" />
1414 </MudPaper >
15+
16+ <MudPaper Width =" 300px" Elevation =" 0" >
17+ <MudText Class =" ma-4" >Complex Type List</MudText >
18+ <MudListExtended T =" ComplexTypes" ItemCollection =" _complexTypeCollection" Clickable =" true" MaxItems =" _maxItems" SearchBox =" _searchBox"
19+ ToStringFunc =" @(e => e?.Name + " " + e?.SurName)" />
20+ </MudPaper >
1521 </MudItem >
1622
1723 <MudItem xs =" 12" sm =" 4" >
2834 int _maxItems = 8 ;
2935 bool _searchBox = false ;
3036 string _selectedState ;
37+ ICollection <ComplexTypes > _complexTypeCollection = new List <ComplexTypes >()
38+ {
39+ new ComplexTypes () { Name = " John" , SurName = " Star" },
40+ new ComplexTypes () { Name = " David" , SurName = " Codewriter" },
41+ new ComplexTypes () { Name = " Mary" , SurName = " Hardcoded" },
42+ new ComplexTypes () { Name = " Jessica" , SurName = " Fastfinger" },
43+ };
3144
3245 private string [] _states =
3346 {
5669 Australia ,
5770 Antarctica
5871 }
72+
73+ public class ComplexTypes
74+ {
75+ public string Name { get ; set ; }
76+ public string SurName { get ; set ; }
77+ }
5978}
You can’t perform that action at this time.
0 commit comments