WPF绑定,后台数据已更新,但前台数据未刷新
1.后台模型类(一般定义主窗口类MainWindow的后台模型类MainWindowModel)中增加命令空间引用using System.ComponentModel;
2.修改类MainWindowModel继承INotifyPropertyChanged,定义事件PropertyChanged;
3.修改被前台绑定的属性set值。
具体参见如下代码:
public class MainWindowModel:INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
#region MES状态
private string _MESState = "离线";
/// <summary>
///
/// </summary>
public string MESState
{
get { return _MESState; }
set
{
if (_MESState != value)
_MESState= value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("MESState"));
}
}
#endregion
}
赞 (0)