@page "/"
@foreach (var item in CheckableEnums)
{
<span> @item.DataPoint.ToString() </span>
<input type="checkbox" @bind="item.IsSelected" />
<br />
}
<br />
@{ SumValue = CheckableEnums.Where(cb => cb.IsSelected).Select(val => val.DataPoint).Aggregate((DataPoints)0,(result, value) => result | value); }
<span>Selected Flags: </span>@SumValue.ToString()
@code {
[Flags]
public enum DataPoints
{
Large = 1,
Soft = 2,
Green = 4,
Round = 8,
LargeAndSoft = 3
}
class CheckableEnum
{
public DataPoints DataPoint { get; set; }
public bool IsSelected;
}
DataPoints SumValue { get; set; }
List<CheckableEnum> CheckableEnums { get; set; } = new List<CheckableEnum>();
protected override void OnInitialized()
{
foreach (var DPvalue in Enum.GetValues(typeof(DataPoints)))
CheckableEnums.Add(new CheckableEnum() { DataPoint = (DataPoints)DPvalue });
}
}