Skip to content

ui::CheckedField

Header: winui/core/Property.hpp.

Derives from ui::Binding< std::optional< bool > >.

The type of a check box's checked (CheckBox, ToggleButton, AppBarToggleButton): true, false or std::nullopt for indeterminate. It is a Binding<std::optional<bool>> that also takes a writable Property<bool> two-way, since a click only ever produces true or false: the property gets each click, and an indeterminate state the app sets on the control writes nothing. A Property<std::optional<bool>> is two-way as everywhere else, and is the one to bind when a click can reach indeterminate (the spec's three_state).

Example:

ui::Property<bool>                agreed{false};
ui::Property<std::optional<bool>> all{false}; // std::nullopt while only some items are on
ui::CheckBox{.text = "I agree", .checked = agreed};     // two-way, two states
ui::CheckBox{.text = "Select all", .checked = all};     // two-way, shows mixed

CheckedField

CheckedField() = default

Unchecked.

CheckedField

CheckedField(Binding<std::optional<bool>> binding)

Any binding of the field's own type: a constant, bind() or bind_one_way().

CheckedField

CheckedField(Property<bool>& source)

A writable Property<bool>, two-way: the same as bind() of it.

CheckedField

CheckedField(TwoWayBinding<bool> two_way)

A two-way binding of a bool (bind() of a Property<bool>, ui::selects()): the control follows it, and a click writes true or false back. An indeterminate state is never written.

writes_bool

bool writes_bool() const noexcept

True when a click writes into a Property<bool>, which cannot hold indeterminate.

selection_group

const void* selection_group() const noexcept

The group of choices it came from, for a binding made by ui::selects(); nullptr otherwise.