XAML綁定問題
<TextBlock Grid.Column="1"
Height="37"
Margin="8,17,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
FontSize="20"
Text="{Binding Contact.Name,
UpdateSourceTrigger=PropertyChanged}" />
C#代碼後面XAML
public partial class Conversation : Window
{
private Friend _Contact;
public Friend Contact
{
get
{
return _Contact;
}
set
{
_Contact = value;
OnPropertyChanged ("Contact");
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged (string propName)
{
if (this . PropertyChanged != null)
this . PropertyChanged (
this , new PropertyChangedEventArgs (propName));
}
#endregion
public Conversation (Friend _Friend)
{
InitializeComponent ();
Contact = _Friend;
}
.
.
.
}
C#朋友類
public class Friend : Person
{
.
.
.
}
C# Person類
public class Person : INotifyPropertyChanged
{
private string _Name;
public string Name
{
get
{
return _Name;
}
set
{
_Name = value;
OnPropertyChanged ("Name");
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged (string propName)
{
if (this . PropertyChanged != null)
this . PropertyChanged (this , new PropertyChangedEventArgs (propName));
}
#endregion
.
.
.
}
我的問題:爲什麼綁定不起作用?
爲什麼? -1? .., 我可以知道嗎 ? – 2011-05-22 21:36:24
因爲你的問題沒有在你身上顯示很多努力,如果綁定不起作用,你至少應該提供產生的綁定錯誤,如果你不知道如何調試綁定,你不應該問爲什麼它會這樣做不工作,但尋找方法[如何做到這一點](http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/30/debugging-data-bindings-in-a-wpf-or-silverlight -application.aspx)。此外,如果您首先閱讀了[介紹性資料](http://msdn.microsoft.com/zh-cn/library/ms752347.aspx),您仍然無法獲得大量的基礎知識。 – 2011-05-23 09:28:35