c# - 单声道上的 Winforms 数据绑定(bind)和 INotifyPropertyChanged

标签 c# winforms mono monodevelop inotifypropertychanged

我制作了我的第一个在树莓派上运行的单声道应用程序。问题是数据绑定(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/

相关文章:

c# - MvxAutoCompleTextView 失去对 PatialText 的绑定(bind)

c# - 可以从 Javascript 使用独立存储吗?

c# - GUI task.wait 与控制台或线程池的死锁

c# - 正确命名 C# 事件和处理程序

c# - 无法将复选框添加到 ToolStrip

c# - 如何在 C# 中调整 Windows 窗体窗体的大小?

.net - 如何获得 .NET TreeView 的 Windows 原生外观?

c# - .Net framework 到底有多跨平台?

c# - 如何使控制台应用程序从 Xamarin studio 中的空项目运行

javascript - 'IJsonHelper' 不包含 'Encode' 的定义