我從空白的全景項目複製了代碼並做了一些調整,但是某處不對。我的數據綁定有什麼問題?
我有我的文字塊設置:
<TextBlock Grid.Column="0" Grid.Row="0" Text="{Binding ElementName=CurrentPlaceNow, Path=Temperature}" />
我的模型看起來是這樣的:
public class CurrentPlaceNowModel : INotifyPropertyChanged
{
#region PropertyChanged()
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
private string _temperature;
public string Temperature
{
get
{
return _temperature;
}
set
{
if (value != _temperature)
{
_temperature = value;
NotifyPropertyChanged("Temperature");
}
}
}
}
而在MainViewModel()
定義定義:
public CurrentPlaceNowModel CurrentPlaceNow = new CurrentPlaceNowModel();
最後我我添加了一個修改器buttonclick:
App.ViewModel.CurrentPlaceNow.Temperature = "foo";
現在,爲什麼沒有任何東西顯示在文本框中?
現貨,謝謝!完全忘記了_CurrentPlaceNow的獲取/設置 – Jason94 2012-03-13 19:42:22