FuncUI
GitHub Repository
  • Getting Started
  • View Basics
    • Creating views
    • Lifetime
    • Attributes
    • How to create bindings
  • Components
    • Component basics
    • Component lifetime
    • Hooks
  • Common Questions
  • Controls
    • Button
    • Border
    • Calendar
    • CalendarDatePicker
    • CheckBox
    • DatePicker
    • DockPanel
    • Expander
    • ListBox
    • Menu
    • NativeMenu
    • NumericUpDown
    • ProgressBar
    • RadioButton
    • RepeatButton
    • Slider
    • StackPanel
    • Tabs
    • TextBlock
    • TextBox
    • TimePicker
    • ToggleButton
    • ToggleSwitch
Powered by GitBook
On this page
  1. Controls

ToggleButton

Last updated 2 years ago

Note: You can check the Avalonia docs for the and if you need more information.

For Avalonia.FuncUI's DSL properties you can check

If you are looking for a button to behave more like a checkbox you can use a ToggleButton. A ToggleButton toggles between checked and unchecked on click.

A ToggleButton is a subclasses of Button so they share all the same attributes as described on that documentation page. A ToggleButton behaves similar to a CheckBox and shares similar attributes like making tristate ToggleButtons.

You need to open Avaloina.Controls.Primatives to access ToggleButton attributes.

Usage

Toggling for Checked/Unchecked

ToggleButton.create [
    ToggleButton.isChecked state.checked
    // Returns a bool value
    ToggleButton.onIsPressedChanged (fun val -> OnChecked val |> dispatch)
]

Handling Checked and Unchecked Differently

ToggleButton.create [
    ToggleButton.onChecked (fun _ -> dispatch Enabled)
    ToggleButton.onUnchecked (fun _ -> dispatch Disabled)
]

Tristate Toggling

ToggleButton.isChecked can take values that are bool, Nullable<bool>, or bool option. When using tristate options however, you must use either Nullable<bool> or bool option. You can also handle each event state like above using onChecked, onUncheked, and onIndeterminate.

ToggleButton.create [
    // can be either true or false
    ToggleButton.isThreeState state.indeterminate
    // this value is required to be either a nullable boolean
    // or a boolean option
    ToggleButton.isChecked state.checked
    // Returns a Nullable<bool> value
    ToggleButton.onIsCheckedChanged (fun nullabelVal -> OnChecked val |> dispatch)
]
ToggleButton
ToggleButton API
ToggleButton.fs