Booleans and enums

Display a bool as an icon or text, and an enum member by its name

Displaying booleans

StellarAdmin displays a bool property with BooleanDisplay, which displays a check mark for true and a cross for false.

The trips grid with a check mark or a cross in the Published column

To display text instead, or an icon and text, set Appearance. The example below displays whether a trip is published as "Live" or "Draft":

using StellarAdmin.Resources.Displays;

columns.Add(trip => trip.IsPublished, column =>
    column.UseDisplay<BooleanDisplay>(flag =>
    {
        flag.Appearance = BooleanDisplayAppearance.Text;
        flag.TrueText = "Live";
        flag.FalseText = "Draft";
    }));
The trips grid with Live or Draft in the Published column

BooleanDisplay has the following members:

MemberDescription
AppearanceDetermines how the value is displayed: BooleanDisplayAppearance.Icon, Text or IconAndText. The default is Icon.
TrueText, FalseTextSpecifies the text for true and false values. The defaults are "Yes" and "No". When only the icon is displayed, screen readers announce the text.

A bool? that is null displays the column's or the field's empty text.

Displaying enums

StellarAdmin displays an enum property with EnumDisplay, which displays the value specified using the member's [Display(Name)] attribute. If the member has no [Display] attribute, EnumDisplay displays the member's name split into words, so NorthAmerica is displayed as "North America".

public enum Difficulty
{
    Easy,

    [Display(Name = "Moderate effort")]
    Moderate,
}

On this page