【发布时间】:2012-03-13 19:16:54
【问题描述】:
我从空白全景图项目中复制了代码并进行了一些调整,但有些地方不对。
我的文本块设置好了:
<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();
最后我为按钮点击添加了一个修饰符:
App.ViewModel.CurrentPlaceNow.Temperature = "foo";
现在,为什么文本框中没有显示任何内容?
【问题讨论】:
标签: c# windows-phone-7 xaml data-binding