Wpf 绑定自定义控件
我有一个可以正常工作的自定义控件,但是我想将部分绑定从Xaml样式移回代码中,这样我的样式就只包含布局信息。例如,如何以编程方式设置IsChecked?下面是我目前的XamlWpf 绑定自定义控件,wpf,data-binding,custom-controls,Wpf,Data Binding,Custom Controls,我有一个可以正常工作的自定义控件,但是我想将部分绑定从Xaml样式移回代码中,这样我的样式就只包含布局信息。例如,如何以编程方式设置IsChecked?下面是我目前的Xaml <CheckBox x:Name="PART_EnabledCheck" Margin="0,3,3,3" IsChecked="{Binding Path=EnabledCheck, Mode=TwoWay, RelativeSource={Relati
<CheckBox x:Name="PART_EnabledCheck" Margin="0,3,3,3"
IsChecked="{Binding Path=EnabledCheck, Mode=TwoWay,
RelativeSource={RelativeSource TemplatedParent}}"/>
您应该可以这样设置绑定:
checkBox.SetBinding(ToggleButton.IsCheckedProperty, new Binding("EnabledCheck")
{
Mode = BindingMode.TwoWay,
RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent)
});
您应该能够如下设置绑定:
checkBox.SetBinding(ToggleButton.IsCheckedProperty, new Binding("EnabledCheck")
{
Mode = BindingMode.TwoWay,
RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent)
});
你为什么要这么做?你为什么要这么做?太好了,谢谢。太好了,谢谢。