WPF Databinding CheckBox.IsChecked

Posted by Adam Tegen on Stack Overflow See other posts from Stack Overflow or by Adam Tegen
Published on 2009-06-18T15:27:48Z Indexed on 2010/05/18 18:10 UTC
Read the original article Hit count: 995

Filed under:
|
|

How would I bind the IsChecked member of a CheckBox to a member variable in my form?

(I realize I can access it directly, but I am trying to learn about databinding and WPF)

Below is my failed attempt to get this working.

XAML:

<Window x:Class="MyProject.Form1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Title" Height="386" Width="563" WindowStyle="SingleBorderWindow">
<Grid>
    <CheckBox Name="checkBoxShowPending" TabIndex="2" Margin="0,12,30,0" Checked="checkBoxShowPending_CheckedChanged" Height="17" VerticalAlignment="Top" HorizontalAlignment="Right" Width="92" Content="Show Pending" IsChecked="{Binding ShowPending}">
    </CheckBox>
</Grid>
</Window>

Code:

namespace MyProject
{
    public partial class Form1 : Window
    {
        private ListViewColumnSorter lvwColumnSorter;

        public bool? ShowPending
        {
            get { return this.showPending; }
            set { this.showPending = value; }
        }

        private bool showPending = false;

        private void checkBoxShowPending_CheckedChanged(object sender, EventArgs e)
        {
            //checking showPending.Value here.  It's always false
        }
    }
}

© Stack Overflow or respective owner

Related posts about wpf

Related posts about databinding