#359 – ToggleButton Basics

The ToggleButton control is similar to the CheckBox control, in that allows the user to toggle something on/off in an application.  Instead of looking like a checkmark next to a label, however, the ToggleButton looks like a normal button.  The button appears to stay pressed in after you click it.  When you click the ToggleButton a second time, it appears to pop back out.

You specify the text that appears on the face of the ToggleButton using the Content property.

        <StackPanel Orientation="Horizontal">
            <ToggleButton Content="Bold" FontWeight="Bold" Padding="5"/>
            <ToggleButton Content="Italic" FontStyle="Italic" Padding="5"/>
            <ToggleButton Padding="5" >
                <TextBlock>
                    <Underline>Underline</Underline>
                </TextBlock>
            </ToggleButton>
        </StackPanel>

Like the CheckBox control, the IsChecked property indicates whether the ToggleButton is currently checked.

Also like the CheckBox control, the Checked and Unchecked events fire when the ToggleButton is checked or unchecked.

Advertisements