2012-07-18 8 views
0

고유 한 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

무엇이 잘못 되었나요?

+0

오류 세부 사항은 당신이 바인딩을 사용하기 위해하는 DependencyProperty를 IsCheckboxChecked 확인해야합니다, 당신은 문제가 무엇인지 알려줍니다. – user7116

답변

2

잘 오류는 매우 분명하다

public static readonly DependencyProperty IsCheckboxCheckedProperty = DependencyProperty.Register("IsCheckboxChecked", typeof(bool), typeof(MyComboBox)); 
public bool IsCheckboxChecked 
{ 
    get { return (bool)GetValue(IsCheckboxCheckedProperty); } 
    set { SetValue(IsCheckboxCheckedProperty, value); } 
} 

대신 :

public bool IsCheckboxChecked { get; set; } 

을 당신은 필드를 IsCheckboxChecked 당신의 DP을해야 그러나 이것은 MycomboBox 클래스가 DependencyObject 클래스를 상속해야한다는 것을 의미합니다 :

public partial class MyCombobox : DependencyObject 

나는이 제안 : http://msdn.microsoft.com/en-gb/library/ms752347.aspx

관련 문제