【问题标题】:Failure to bind StringElement.Visible to boolean property in ViewModel未能将 StringElement.Visible 绑定到 ViewModel 中的布尔属性
【发布时间】:2013-10-28 11:14:25
【问题描述】:

在我在 Mac 上的 Xamarin Studio 项目中,我使用来自 MvvmCross-Binaries 的 MvvmCross 版本 3.0.13,XS-iOS-Mac Release 程序集,并且我正在尝试将我的 CrossUI Dialog 基于 View 和对应的 ViewModel。具体来说,我在我的对话框视图中定义了Root,如下所示:

var bindings = this.CreateInlineBindingTarget<ViewModel>();
Root = new RootElement("New Connection") {
  new Section {
    new StringElement("Test")
      .Bind(bindings, element => (object)element.SelectedCommand, vm => vm.TestConnection)
  },
  new Section {
    new StringElement ("Add")
      .Bind (bindings, element => element.Visible, vm => vm.CanAddConnection)
      .Bind (bindings, element => (object)element.SelectedCommand, vm => vm.AddConnection)
  }
};

ViewModel 中,如果测试成功,CanAddConnection 将通过 TestConnection 命令设置为 true

当我运行它(在 iOS 模拟器中)并打开对话框时,会显示 Test 按钮并隐藏 Add 按钮(如预期的那样)。当我单击按钮并且测试成功时,Add 按钮未显示,而是在应用程序输出中收到此消息:

这是怎么发生的 - CurrentAttachedCell 是非 UITableView 的子项

为什么我的可见绑定不起作用?


据我所知,我没有在上游进行任何会导致代码中出现this failure 的代码自定义(但我可能会遗漏一些东西)。

如果我将CanAddConnection 绑定到另一个元素属性,例如Caption,布尔值会在视图中正确更新。

【问题讨论】:

    标签: c# ios mvvmcross monotouch.dialog


    【解决方案1】:

    我认为您可能对作为 https://github.com/MvvmCross/MvvmCross/issues/467 一部分的 ios7 更改进行了处理

    此修复将包含在 3.0.14 中(希望在下周) - 同时,最简单的解决方法可能是在您自己的构建中修补 UpdateVisibility - 或实现自定义 StringElement

    【讨论】:

    • 我在谷歌上搜索这个问题时实际上找到了那个页面,但我无法立即意识到它与我的问题有关。目前,我最好等待 3.0.14 版本,而不是设置和构建补丁程序集,但无论如何,非常感谢@Stuart,帮助我解决了这个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-28
    • 2011-08-26
    • 2015-01-25
    • 2011-08-26
    • 2016-09-26
    • 1970-01-01
    相关资源
    最近更新 更多