locked
Checkbox Databinding RRS feed

  • Question

  • How do I do databinding on a checkbox?
    Certified Geek. Data dude.
    Friday, May 29, 2009 1:37 PM

Answers

  • You normally bind IsChecked property to a boolean.
    • Marked as answer by Garvander Friday, May 29, 2009 2:00 PM
    Friday, May 29, 2009 1:58 PM
  • Are you looking to bind to it in XAML or in code? In XAML, the syntax is fairly straightforward:

    <CheckBox IsChecked="{Binding PropertyName}" />

    In code you have to declare a binding and set it up manually:

    CheckBox checkBox = new CheckBox();

    Binding binding = new Binding("SomeProperty");
    binding.Source = someDataSource;
    BindingOperations.SetBinding(checkBox, CheckBox.IsCheckedProperty, binding);
    • Marked as answer by Garvander Friday, May 29, 2009 3:00 PM
    Friday, May 29, 2009 2:00 PM

All replies

  • You normally bind IsChecked property to a boolean.
    • Marked as answer by Garvander Friday, May 29, 2009 2:00 PM
    Friday, May 29, 2009 1:58 PM
  • Are you looking to bind to it in XAML or in code? In XAML, the syntax is fairly straightforward:

    <CheckBox IsChecked="{Binding PropertyName}" />

    In code you have to declare a binding and set it up manually:

    CheckBox checkBox = new CheckBox();

    Binding binding = new Binding("SomeProperty");
    binding.Source = someDataSource;
    BindingOperations.SetBinding(checkBox, CheckBox.IsCheckedProperty, binding);
    • Marked as answer by Garvander Friday, May 29, 2009 3:00 PM
    Friday, May 29, 2009 2:00 PM