【发布时间】:2009-04-25 15:06:46
【问题描述】:
我在Window (ArtistInfo) 中有以下 Xaml:
<Grid>
<TextBlock Text="{Binding Artist.Name}"></TextBlock>
</Grid>
这是同一窗口的代码隐藏(为了问题而简化的代码):
public static readonly DependencyProperty ArtistProperty =
DependencyProperty.Register("Artist", typeof(Artist), typeof(ArtistInfo));
Artist Artist {
get {
return (Artist)GetValue(ArtistProperty);
}
set {
SetValue(ArtistProperty, value);
}
}
public ArtistInfo() {
InitializeComponent();
}
public ArtistInfo(int artistID) {
InitializeComponent();
Artist = GetArtist(artistID);
}
基本上我想要做的是数据绑定到一个依赖属性,这样当Artist 被填充(在构造函数中)时,TextBlock 被填充艺术家的名字。
我在这里缺少什么?
【问题讨论】:
标签: c# wpf data-binding xaml dependency-properties