【问题标题】:Use Mvvmcross Binding with MonoTouch.Dialog (Lists and Commands)将 Mvvmcross 绑定与 MonoTouch.Dialog 一起使用(列表和命令)
【发布时间】:2013-08-25 09:33:00
【问题描述】:

1.绑定列表

我想知道如何将 ObservableCollection 绑定到 Radiogroup:

new Section(){
                new RootElement("Mandanten", new RadioGroup("mandanten", 2)) {
                    new Section(){
                        new RadioElement("Kupus", "mandanten"),
                        new RadioElement("Kajmak", "mandanten")
                    }
                }
            }

正如您在此处看到的,我正在手动创建 2 个项目/元素,但我错过了诸如“ItemsSource”之类的内容。 如果不可能,你会给我什么建议?使用女巫控制(绑定列表)?

2。命令绑定

我看到 MonoTouch.Dialog 中没有“按钮”。所以我看到我们将使用“StringElement”。 我试过了,但点击“按钮”后什么也没发生:

new StringElement("Login").Bind(this, "SelectedCommand LoginCommand")

我不知道出了什么问题,也许我需要在这里使用新的“变体”,就像这样:

new EntryElement ("User", "Loginuser", ViewModel.User).Bind(target, v => v.Value, t => t.User),

但我不确定如何构建类似的代码来绑定特定“字符串元素”的命令(在这种情况下 - 带有 ontap 事件的按钮)..

任何帮助表示赞赏!

【问题讨论】:

  • 如果可以的话,请每个问题问一个问题 - 使其更易于阅读、搜索和回答

标签: binding xamarin.ios mvvmcross monotouch.dialog


【解决方案1】:

1。绑定列表

绑定动态ObservableCollection 列表的示例位于https://github.com/slodge/MvvmCross-Tutorials/blob/master/DialogExamples/DialogExamples.Touch/Views/ThirdView.cs - 它使用来自https://github.com/slodge/MvvmCross-Tutorials/tree/master/DialogExamples/DialogExamples.Touch/BindableElements 的一些自定义元素 - 基于来自https://github.com/asednev/MvvmCross.AlexeysExtensions 的示例

由于 Radio 列表在内部实现的方式,我不知道相同的 ObservableCollection 绑定方法是否适用于 radio 列表 - 需要有人进行原型设计和试验才能解决这个问题。但是,https://github.com/slodge/MvvmCross-Tutorials/blob/master/DialogExamples/DialogExamples.Touch/Views/FirstView.cs中显示了一个简单的固定电台列表

2。命令绑定

查看示例:https://github.com/slodge/MvvmCross-Tutorials/blob/master/DialogExamples/DialogExamples.Touch/Views/FirstView.cs

                new Section("Action")
                    {
                        new StringElement("Second").Bind(bindings, element => element.SelectedCommand, vm => vm.GoSecondCommand),
                        new StringElement("Bindable Elements").Bind(bindings, element => element.SelectedCommand, vm => vm.BindableElementsCommand)  
                    },

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-15
    • 2014-07-04
    • 2017-08-18
    • 2016-07-28
    • 1970-01-01
    • 2014-03-29
    • 1970-01-01
    • 2014-06-29
    相关资源
    最近更新 更多