Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.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# 对象属性的数据绑定失败,无法绑定到正在工作的父对象_C#_Wpf_Data Binding_Binding_Nested - Fatal编程技术网

C# 对象属性的数据绑定失败,无法绑定到正在工作的父对象

C# 对象属性的数据绑定失败,无法绑定到正在工作的父对象,c#,wpf,data-binding,binding,nested,C#,Wpf,Data Binding,Binding,Nested,我试图将属性绑定到嵌套对象,但失败了 我已经看了这些问题,但我想我在其他地方犯了另一个错误。也许有人能给我一点帮助 上滑块/文本框的绑定正确,而下滑块/文本框的绑定错误 我有两个带有腐蚀性文本框的滑块: <StackPanel> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> <TextBox Text="{Binding Path= boundnumber, Mo

我试图将属性绑定到嵌套对象,但失败了

我已经看了这些问题,但我想我在其他地方犯了另一个错误。也许有人能给我一点帮助

上滑块/文本框的绑定正确,而下滑块/文本框的绑定错误

我有两个带有腐蚀性文本框的滑块:

<StackPanel>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
    <TextBox Text="{Binding Path= boundnumber, Mode=TwoWay, FallbackValue='binding failed'}" ></TextBox>
    <Slider Value="{Binding Path= boundnumber, Mode=TwoWay}" Width="500" Maximum="1000" ></Slider>
</StackPanel>

    <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" DataContext="{Binding Path=myDatarow}">

        <TextBox Text="{Binding Path= boundnumber, Mode=TwoWay, FallbackValue='binding failed'}" ></TextBox>
        <Slider Value="{Binding Path= boundnumber, Mode=TwoWay}" Width="500" Maximum="1000" ></Slider>
</StackPanel>
</StackPanel>

您需要将您的
myDatarow
公开到一个公共属性中,如
boundnumber

    private DataRow _myDatarow = new DataRow(11);
    public DataRow myDataRow
    {
        get { return _myDatarow; }
    }
还有一个额外的建议。
最好将您的
DataContext
类与
main窗口分开

。解决此问题的关键是将类本身声明为公共类
    private DataRow _myDatarow = new DataRow(11);
    public DataRow myDataRow
    {
        get { return _myDatarow; }
    }