Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 绑定自定义控件_Wpf_Data Binding_Custom Controls - Fatal编程技术网

Wpf 绑定自定义控件

Wpf 绑定自定义控件,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

我有一个可以正常工作的自定义控件,但是我想将部分绑定从Xaml样式移回代码中,这样我的样式就只包含布局信息。例如,如何以编程方式设置IsChecked?下面是我目前的Xaml

<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)
});

你为什么要这么做?你为什么要这么做?太好了,谢谢。太好了,谢谢。