WPF How to Check IsChecked Binding in Code Behind

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

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

How to copy this in code?

+3
source share
1 answer

Something like that:

CheckBox myCheckBox = new CheckBox();
myCheckBox.HorizontalAlignment = HorizontalAlignment.Center;
myCheckBox.VerticalAlignment = VerticalAlignment.Center;
myCheckBox.SetBinding(ToggleButton.IsCheckedProperty, "DataItem.IsChecked");
+3
source

Source: https://habr.com/ru/post/1791426/


All Articles