对于所有子属性数据绑定,不会通知C#WPF依赖项属性

时间:2017-07-22 02:20:13

标签: wpf data-binding dependency-properties

这是我的代码,我正在编写一个带有Dependency属性的简单WPF应用程序,我在这些子属性的数据绑定中失败,但是在那些普通属性中工作,例如string,int。有什么想法吗?

<!-- Work -->
<TextBlock Grid.Column="1" VerticalAlignment="Center" Text="{Binding address}"/>
<!-- Not work -->
<TextBlock Grid.Column="1" VerticalAlignment="Center" Text="{Binding child.Name}"/>


public class Child
{
    public String Name { get; set; }
}

public Child child
{
    get { return (Child)GetValue(childProperty); }
    set { SetValue(childProperty, value); }
}

public static readonly DependencyProperty childProperty =
    DependencyProperty.Register("child", typeof(Child), typeof(MainWindow), new PropertyMetadata(null));


public String address
{
    get { return (String)GetValue(addressProperty); }
    set { SetValue(addressProperty, value); }
}

public static readonly DependencyProperty addressProperty =
    DependencyProperty.Register("address", typeof(String), typeof(MainWindow), new PropertyMetadata(null));

0 个答案:

没有答案
相关问题