Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF How to set checkbox IsChecked binding in code behind

Tags:

wpf

I have a style that I have to create in code-behind. It has a checkbox that looks like this..

<CheckBox 
              HorizontalAlignment="Center"
              VerticalAlignment="Center"
              IsChecked="{Binding Path=DataItem.IsChecked}"
              >
</CheckBox>

How do I replicate this in code-behind?

like image 942
Aks Avatar asked Feb 11 '11 08:02

Aks


1 Answers

Something like this:

CheckBox myCheckBox = new CheckBox();
myCheckBox.HorizontalAlignment = HorizontalAlignment.Center;
myCheckBox.VerticalAlignment = VerticalAlignment.Center;
myCheckBox.SetBinding(ToggleButton.IsCheckedProperty, "DataItem.IsChecked");
like image 150
Pavlo Glazkov Avatar answered Nov 15 '22 08:11

Pavlo Glazkov