我在Window
(ArtistInfo
)中有以下Xaml:WPF:關於依賴屬性的基本問題
<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
將填充Artist的名稱。
我在這裏缺少什麼?
+1感謝您展示xaml Kent如何完成它 – 2009-04-25 15:19:31