这是我的代码,我正在编写一个带有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));