SwitchButton

in namespace DotVVM.BusinessPack.Controls

Usage & Scenarios

Renders the button that can switch states like the CheckBox

Sample 1: Basic Usage

The SwitchButton control has the Checked property of boolean which indicates whether the control is checked or not.

You can use the Text property to specify the button text. Or you can put contents inside the bp:SwitchButton element.

<bp:SwitchButton Text="Switch button"
                 Checked="{value: Checked}">
</bp:SwitchButton>
using System;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.SwitchButton.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public bool Checked { get; set; }
    }
}

Sample 2: Click Event

You can set which command will be triggered when the button is clicked with click property.

<bp:SwitchButton Checked="{value: Checked}"
                 Click="{command: ClickCount = ClickCount + 1}">
    <span>Switch button</span> &nbsp;
</bp:SwitchButton>

<p>Click counter: {{value: ClickCount}}</p>
using System;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.SwitchButton.sample2
{
    public class ViewModel : DotvvmViewModelBase
    {
        public bool Checked { get; set; }
        public int ClickCount { get; set; }
    }
}

Properties

Name Type Description Notes Default Value
property icon Checked Boolean Gets or sets whether the button is checked. The value is changed when the button is clicked, right before the Click command is triggered. The default value is false.
attribute
inner element
static value
bindable
default
False
property icon DisableContentStyle Boolean
attribute
inner element
static value
bindable
default
False
property icon Enabled Boolean Gets or sets a value indicating whether the button is enabled and can be clicked on.
attribute
inner element
static value
bindable
default
True
property icon Text String Gets or sets the text displayed on the button.
attribute
inner element
static value
bindable
default

Events

Name Type Description
event icon Click Command Gets or sets the command triggered when the button is clicked.

HTML produced by the control