WPF: XAML checkbox

This entry is part 16 of 54 in the series Learn WPF

If we have the checkbox in the XAML, it will be easier to format the checkbox as compared to using code to do the formatting.

<Window x:Class="CheckBox1.MainWindow"
        Title="MainWindow" Height="350" Width="525">
        <CheckBox Name="cb" Checked="cb_checked" Unchecked="cb_unchecked" Margin="50, 50, 50, 50" FontSize="24" >Check Box</CheckBox>

using System.Windows;
using System.Windows.Controls;

namespace CheckBox1
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
        public MainWindow()
        private void cb_checked(object sender, RoutedEventArgs e)
            cb.Content = "Checked";

        private void cb_unchecked(object sender, RoutedEventArgs e)
            cb.Content = "Unchecked";

The output from running the above code will be as below.  You can try clicking on the checkbox.




Series Navigation<< WPF: Checkbox status
WPF: Checkbox isChecked >>

Leave a comment

Leave a Reply