Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.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
C# 绑定到所属对象属性的XAML_C#_Wpf_Xaml_Silverlight_Binding - Fatal编程技术网

C# 绑定到所属对象属性的XAML

C# 绑定到所属对象属性的XAML,c#,wpf,xaml,silverlight,binding,C#,Wpf,Xaml,Silverlight,Binding,我正在编写Silverlight应用程序。My MainPage对象拥有另一个实现INotifyPropertyChanged接口并包含bool CLR属性的对象: public partial class MainPage: INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; CustomObject customObject = ... // was creat

我正在编写Silverlight应用程序。My MainPage对象拥有另一个实现INotifyPropertyChanged接口并包含bool CLR属性的对象:

public partial class MainPage: INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    CustomObject customObject = ... // was created successfully

    CheckBox checkBox = ... // is actually created in in XAML

    // this is only for testing purposes
    public bool IsIncluded
    {
        get { ... }
        set {
            // ...
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("IsIncluded"));
        }
    }
}

public partial class CustomObject: INotifyPropertyChanged
{
    public bool IsIncluded
    {
        get { ... }
        set {
            // ...
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("IsIncluded"));
        }
    }
}
My MainPage.xaml包含

<CheckBox IsChecked="{Binding Path=IsIncluded,Mode=OneWay}" />
<CheckBox IsChecked="{Binding Path=customObject.IsIncluded,Mode=OneWay}" />

第一次装订效果很好。第二个不是。我需要第二个来工作。我如何才能做到这一点?

CustomObject客户对象=。。。。看起来像私有字段,无法绑定到字段。如果在这种情况下,您需要将其转换为公共属性public CustomObject CustomObject with property Changed如果在绑定通过XAML连接后分配了CustomObject,那么您需要在CustomObject属性的MainPage类上实现InotifyProperty Changed,您也可能已经完成了此操作,但如果是这样的话,你发布的代码中就没有。
CustomObject _customObject = ... // was created successfully
    public CustomObject customObject
    {
        get { return _customObject ; }
        set {
            _customObject  = value;

            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("customObject"));
            }
    }