Bound<TValue> class Core

One property of a view model, mirrored for the controls of a board. The controls draw Bound.Value, a copy the board takes on the UI thread inside Board.Mutate whenever the view model raises INotifyPropertyChanged.PropertyChanged for the property, from any thread. What the user enters goes back through Bound.Set.

Made by board.Bind(viewModel, x => x.Name). A control whose value is a pair of delegates takes it as it is: new CheckBox { Value = active.Get, Toggle = active.Toggle }, or Value = amount.Get, Changed = amount.Set. A control that holds its value itself (a TextBox) is bound through an IBindingAdapter with board.Bind(control, adapter, viewModel, x => x.Name).

The copy is the point: the render thread reads it and never the view model, and the board finds what changed by comparing its tiles before and after the copy is taken. The copy itself is read from the view model on the UI thread, after the change was raised: a view model written on a worker thread must be safe to read from the UI thread meanwhile (a single field is; a pair of fields that belong together needs the view model's own lock).

Lifetime: the view model holds the binding only weakly, so a form that is dropped without Bound.Dispose does not stay alive through a long-lived view model. While the board's view is detached from its host the binding does not listen; when it is attached again the copy is taken anew.

public sealed class Bound<TValue> : IDisposable, IBindingEntry
Namespace
ArionUI.Presentation.Controls
Package
ArionUI.Presentation · dotnet add package ArionUI.Presentation --prerelease
Implements
IDisposable, IBindingEntry

Type parameters

TValue

The property's type.

Properties

CanWrite

public bool CanWrite { get; }

False when the property has no public setter of exactly TValue: the binding is then one-way, and Bound.Set throws.

PropertyName

public string PropertyName { get; }

The name of the bound property, as INotifyPropertyChanged reports it.

Value

public TValue Value { get; }

The value the controls show: the view model's, as the board last took it.

Methods

Dispose

public void Dispose();

Stops listening for this property; the controls keep the last value.

Get

public TValue Get();

Bound.Value as a method, for a control's value delegate (Value = bound.Get).

Set

public void Set(TValue newValue);

Writes newValue into the view model: what the user entered. UI thread only, like every change of a shown board; it runs inside Board.Mutate, so what the write changes elsewhere on the board (a total, a label) repaints with it. The view model may keep another value (round, trim, refuse): Bound.Value is what it kept.