Elements

Label

A text display element for showing read-only text content. Extends BaseElement functionality.

Constructor

new Label("Hello World");
new Label(); // Empty label
new Label(observable); // Bound to observable

Examples

ReactiveProperty Binding

Labels display reactive text from ReactiveProperty fields:

var UserName = new ReactiveProperty<string>("Player1");
var WelcomeMessage = new ReactiveProperty<string>("Welcome!");
var Count = new ReactiveProperty<int>(0);

// Direct binding to ReactiveProperty
new Label().BindText(UserName);

// Constructor binding (preferred for simple cases)
new Label(WelcomeMessage);

// Transform the observable value
new Label().BindText(Count.Select(count => $"Items: {count}"));

Conditional Styling

Use BindClassName to reactively apply styles:

var StatusMessage = new ReactiveProperty<string>("");
var HasError = new ReactiveProperty<bool>(false);
var IsSuccess = new ReactiveProperty<bool>(false);

new Label().BindText(StatusMessage)
    .BindClassName("error", HasError)
    .BindClassName("success", IsSuccess);

// Multiple conditional classes
var PlayerName = new ReactiveProperty<string>("Player1");
var IsOnline = new ReactiveProperty<bool>(true);
var IsModerator = new ReactiveProperty<bool>(false);

new Label(PlayerName)
    .BindClassName("online", IsOnline)
    .BindClassName("moderator", IsModerator);

Computed Values

Combine multiple ReactiveProperties for complex displays:

var Health = new ReactiveProperty<int>(100);
var MaxHealth = new ReactiveProperty<int>(100);
var Score = new ReactiveProperty<int>(0);

// Combine multiple observables
new Label().BindText(
    Health.CombineLatest(MaxHealth)
        .Select(values => $"Health: {values.First}/{values.Second}")
);

// Complex formatting
new Label().BindText(
    Score.Select(score => $"Score: {score:N0} points")
);

Properties

PropTypeDefault
text?
string
""
disabled?
bool
false
visible?
bool
true
name?
string
""
pickingMode?
PickingMode
PickingMode.Position

Methods

PropTypeDefault
Text?
(string) => Label
-
GetText?
() => string
-
BindText?
(Observable<string>) => Label
-
Disabled?
(bool = true) => Label
-
GetDisabled?
() => bool
-
BindDisabled?
(Observable<bool>) => Label
-
Visible?
(bool) => Label
-
GetVisible?
() => bool
-
BindVisible?
(Observable<bool>) => Label
-
ClassName?
(string, bool = true) => Label
-
BindClassName?
(string, Observable<bool>) => Label
-
StyleSheet?
(StyleSheet) => Label or (string) => Label
-

Label extends BaseElement.