Hi David,
Query: how
to initialize data binding in C#
We have prepared a simple sample to bind the properties of
SfCheckBox in code behind. Please refer the below code.
Code snippet [C#]:
var binding = new Binding() { Source = viewModel, Path = "IsActive", Mode =
BindingMode.TwoWay };
SfCheckBox sfCheckBox = new SfCheckBox(); sfCheckBox.SetBinding(SfCheckBox.IsCheckedProperty, binding); |
Sample - https://www.syncfusion.com/downloads/support/forum/150675/ze/150675-sample-365345168.zip
Please get back to us if you need further assistance on this.
Regards,
Geetha R.
foreach(Model model in viewModel.Data)
{
var binding = new Binding()
{
Source = model,
Path = "IsChecked",
Mode = BindingMode.TwoWay
};
Binding textbinding = new Binding()
{
Source = model,
Path = "Name",
Mode = BindingMode.TwoWay
};
SfCheckBox sfCheckBox = new SfCheckBox();
sfCheckBox.SetBinding(SfCheckBox.TextProperty, textbinding);
sfCheckBox.SetBinding(SfCheckBox.IsCheckedProperty, binding);
layout.Children.Add(sfCheckBox);
} |