开发者

WPF How to set checkbox IsChecked binding in code behind

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

<CheckBox 
     开发者_C百科         HorizontalAlignment="Center"
              VerticalAlignment="Center"
              IsChecked="{Binding Path=DataItem.IsChecked}"
              >
</CheckBox>

How do I replicate this in code-behind?


Something like this:

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


var myCheckBox = new CheckBox() {DataContext = DataItem };
myCheckBox.SetBinding(ToggleButton.IsCheckedProperty, new Binding(nameof(DataItem.IsChecked));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜