将 Mvvmcross 绑定与 MonoTouch.Dialog(列表和命令)结合使用 [英] Use Mvvmcross Binding with MonoTouch.Dialog (Lists and Commands)
问题描述
1.绑定列表
我想知道如何将 ObservableCollection 绑定到 Radiogroup:
I wonder how I could bind a ObservableCollection to a Radiogroup:
new Section(){
new RootElement("Mandanten", new RadioGroup("mandanten", 2)) {
new Section(){
new RadioElement("Kupus", "mandanten"),
new RadioElement("Kajmak", "mandanten")
}
}
}
正如您在此处看到的,我正在手动创建 2 个项目/元素,但我错过了诸如ItemsSource"之类的东西.如果不可能,你会给我什么建议?使用女巫控制(绑定列表)?
as you see here I'm creating 2 Items/Elements manually but I miss something like an "ItemsSource". If its not possible, what recommendation would you give me? To use witch Control (to bind Lists)?
2.命令绑定
正如我所见,MonoTouch.Dialog 中没有按钮".所以我看到我们将使用StringElement".我试过了,但点击按钮"后什么也没发生:
As I see theres no "button" in MonoTouch.Dialog. So I saw that we'll use "StringElement". I tried it, but after tapping on the "button" nothing happened:
new StringElement("Login").Bind(this, "SelectedCommand LoginCommand")
我不确定出了什么问题,也许我需要在这里使用新的变体",如下所示:
I'm not sure whats wrong, maybe I need to use here the new "variant", like that:
new EntryElement ("User", "Loginuser", ViewModel.User).Bind(target, v => v.Value, t => t.User),
但我不确定如何构建类似的代码来绑定特定字符串元素"的命令(在这种情况下 - 带有 ontap 事件的按钮)..
But I'm not sure how to build that similiar code to bind a command for a particular "stringelement" (in that case - a button with the ontap event)..
感谢任何帮助!
推荐答案
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/asdnev/MvvmCross.AlexeysExtensions
1. Binding lists
An example of binding dynamic ObservableCollection
lists is in https://github.com/slodge/MvvmCross-Tutorials/blob/master/DialogExamples/DialogExamples.Touch/Views/ThirdView.cs - it uses some custom elements from https://github.com/slodge/MvvmCross-Tutorials/tree/master/DialogExamples/DialogExamples.Touch/BindableElements - which was based on the sample from https://github.com/asednev/MvvmCross.AlexeysExtensions
由于 Radio 列表在内部实现的方式,我不知道相同的 ObservableCollection
绑定方法是否适用于 Radio List - 有人需要原型和实验来解决这个问题.但是,一个简单的固定单选列表显示在 https://github.com/slodge/MvvmCross-Tutorials/blob/master/DialogExamples/DialogExamples.Touch/Views/FirstView.cs
Because of the way Radio lists are internally implemented, I don't know if the same ObservableCollection
binding approach would work for radio lists - someone would need to prototype and experiment to work this out. However, a simple fixed radio list is shown in 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)
},
这篇关于将 Mvvmcross 绑定与 MonoTouch.Dialog(列表和命令)结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!