고유 한 ComboBoxItem을 만듭니다. 여기에서는 코드를 단순화했습니다. ComboBoxItem에는 CheckBox가 있습니다.MyCombobox와 바인딩 속성을 바인딩 할 수 없습니다.
ComboBoxItem 컨트롤의 XAML :
<ComboBoxItem x:Class="WpfApplication1.MyCombobox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="50"
Width="200">
<!-- ... -->
<StackPanel>
<CheckBox IsChecked="{Binding Path=IsCheckboxChecked}" IsEnabled="{Binding Path=IsCheckboxEnabled}">
<CheckBox.LayoutTransform>
<ScaleTransform ScaleX="1" ScaleY="1" />
</CheckBox.LayoutTransform>
</CheckBox>
<!-- ... -->
</StackPanel>
</ComboBoxItem>
ComboBoxItem 컨트롤 C#을 (코드 숨김)
public partial class MyCombobox
{
public MyCombobox()
{
InitializeComponent();
DataContext = this;
//Defaults
IsCheckboxChecked = false;
IsCheckboxEnabled = true;
//...
}
//...
public string Text { get; set; }
public bool IsCheckboxChecked { get; set; }
public bool IsCheckboxEnabled { get; set; }
//...
}
와 내가 그렇게 포함 : 내 응용 프로그램을 실행할 때
<WpfApplication1:MyCombobox IsCheckboxChecked="{Binding Path=IsMyCheckBoxChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsCheckboxEnabled="{Binding Path=IsMyCheckBoxEnabled, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Text="Write your Text here" />
나는이 얻을 오류 :
A fatal error occurred: a 'Binding' cannot be set on the 'IsCheckboxChecked' property of type 'MyCombobox'. A 'Binding' can only be set on a Dependency Property of a DependencyObject
무엇이 잘못 되었나요?
오류 세부 사항은 당신이 바인딩을 사용하기 위해하는 DependencyProperty를 IsCheckboxChecked 확인해야합니다, 당신은 문제가 무엇인지 알려줍니다. – user7116