【发布时间】:2009-04-07 09:10:52
【问题描述】:
我有一个关于数据绑定的问题。
我的 xaml.cs 文件中有以下属性:
private string _stationIdInstruction;
public event PropertyChangedEventHandler PropertyChanged;
public string StationIdInstruction
{
get { return _stationIdInstruction; }
set
{
_stationIdInstruction = value;
OnPropertyChanged("StationIdInstruction");
}
}
protected void OnPropertyChanged(string name)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
如何将 TextBlock 绑定到 StationIdInstructions,以便它在我更新 StationIdInstructions 时将字符串属性作为其 Text 并更新 TextBlock.Text。
感谢任何帮助。
【问题讨论】:
-
您的源代码有一个小错误:您在“if (PropertyChanged != null)”之后忘记了开头的“{”,或者您正在关闭一个不存在的 if 块。跨度>