我制作了我的第一个在树莓派上运行的单声道应用程序。问题是数据绑定(bind)没有更新 UI。更具体地说,我的 Controller /模型中的 PropertyChanged 事件为空。这意味着没有订阅者。
当我在 visual studio 调试器中的 Windows 上运行应用程序时,ui 得到正确更新。
单声道版本:4.6.2 操作系统:Raspbian Wheezy .NET:4.5
我没有找到太多关于该场景的信息。由于它在 Windows 上运行并且单声道支持 INotifyPropertyChanged 接口(interface),我假设它也可以在 Linux 上以单声道运行。
//在代码中创建绑定(bind)
dhtControl.labelName.DataBindings.Add("文本", dht, "名称");
我认为不需要其他代码,因为它是默认的 INotifyPropertyChanged 实现。唯一的区别是我将一个 Action (control.Invoke) 传递给模型以在主线程上调用更新。
问候
最佳答案
我有同样的问题,解决了添加由 ViewModel 触发的 Action 事件,其中更新所有控件:
internal void InvokeUIControl(Action action)
{
// Call the provided action on the UI Thread using Control.Invoke() does not work in MONO
//this.Invoke(action);
// do it manually
this.lblTemp.Invoke(new Action(() => this.lblTemp.Text = ((MainViewModel)(((Delegate)(action)).Target)).Temperature));
this.lblTime.Invoke(new Action(() => this.lblTime.Text = ((MainViewModel)(((Delegate)(action)).Target)).Clock));
}
关于c# - 单声道上的 Winforms 数据绑定(bind)和 INotifyPropertyChanged,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42189980/