Reputation: 957
I have a custom control which is working fine but I would like to move the binding of the parts from the Xaml Style back into the code so that my style only contains layout information. For example how would I set the IsChecked programmatically? Below is my current Xaml for it.
<CheckBox x:Name="PART_EnabledCheck" Margin="0,3,3,3"
IsChecked="{Binding Path=EnabledCheck, Mode=TwoWay,
RelativeSource={RelativeSource TemplatedParent}}"/>
Upvotes: 0
Views: 77
Reputation: 13611
You should be able set the binding like this:
checkBox.SetBinding(ToggleButton.IsCheckedProperty, new Binding("EnabledCheck")
{
Mode = BindingMode.TwoWay,
RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent)
});
Upvotes: 2