我在读取更改后的值时遇到问题:
在XAML中绑定:
Text="{Binding Path=Infotext,Mode=TwoWay}"
我尝试通过以下方式读取值(绑定到文本框,类为票证,ic_Tickets是带有“票证”的Items控件):
string text=((ObservableCollection<Ticket>)ic_Tickets.ItemsSource).Where(Ticket => Ticket.id == ((MenuItem)sender).Tag.ToString()).First().Infotext;
与此(在公共类Ticket:INotifyPropertyChanged中,我得到了旧的绑定值
public string Infotext { get
{
return Infotext_int;
}
set {
Infotext_int = value;
NotifyPropertyChanged();
} }
但是如果我添加这样的消息框:
public string Infotext { get
{
return Infotext_int;
}
set {
Infotext_int = value;
MessageBox.Show("!!!"); //or inside the NotifyPropertyChanged()
NotifyPropertyChanged();
} }
我获得了新的价值...(我想要新的价值,但始终无法显示消息框的方式)
因此,只有当消息框显示为oO时,它才会将新值设置为Itemssource
通知功能:
private void NotifyPropertyChanged(String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this,new PropertyChangedEventArgs(propertyName));
}
}