MvvmCross Android Dialog程序化绑定

3
我希望您能够在我的MvvmCross项目中使用Android.Dialog (Cross.UI)。 我的第一步是使用AutoViews。由于这个功能仍然相对较新,所以另一个选择是在touch和Droid平台上实现对话框。
目前,我只需要为Droid编写代码,并且需要以编程方式将ViewModel的属性绑定到对话框的元素。
以下是我的View和ViewModel代码:
    public class DialogConfigurationView : MvxBindingDialogActivityView<DialogConfigurationViewModel>
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            DroidResources.Initialise(typeof(Resource.Layout));

            Root = new RootElement()
                {
                    new Section("Private Configuration")
                        {
                            new EntryElement("Name:"),
                            new EntryElement("Description:"),
                            new BooleanElement("Active?")
                        }
                };
        }
    }

ViewModel

    public class DialogConfigurationViewModel : MvxViewModel
    {
        public ConfigurationSet Configuration
        {
            get { return _configuration; }
            set
            {
                if (_configuration != value)
                {
                    _configuration = value;
                    RaisePropertyChanged(() => Configuration);
                }
            }
        }
        private ConfigurationSet _configuration;
    }

我的目标是将EntryElement("Name:")与属性ViewModel.Configuration.Name进行双向绑定。有人能帮助我吗?这可以实现吗?
1个回答

2
我不知道是否有任何 monodroid.dialog mvvmcross 的样例没有使用 autoviews!但是......绑定的基本语法应该与 MonoTouch.Dialog 相同,例如:
                            new Section("Contact Info")
                                {
                                    new StringElement("ID", ViewModel.Customer.ID ?? string.Empty),
                                    new EntryElement("Name", "Name").Bind(this, "{'Value':{'Path':'Customer.Name'}}"),
                                    new EntryElement("Website", "Website").Bind(this, "{'Value':{'Path':'Customer.Website'}}"),
                                    new EntryElement("Primary Phone", "Phone").Bind(this, "{'Value':{'Path':'Customer.PrimaryPhone'}}"),
                                },
                            new Section("Primary Address")
                                {
                                    new EntryElement("Address").Bind(this, "{'Value':{'Path':'Customer.PrimaryAddress.Street1'}}"),
                                    new EntryElement("Address2").Bind(this, "{'Value':{'Path':'Customer.PrimaryAddress.Street2'}}"),
                                    new EntryElement("City").Bind(this, "{'Value':{'Path':'Customer.PrimaryAddress.City'}}"),
                                    new EntryElement("State").Bind(this, "{'Value':{'Path':'Customer.PrimaryAddress.State'}}"),
                                    new EntryElement("Zip").Bind(this, "{'Value':{'Path':'Customer.PrimaryAddress.Zip'}}"),
                                },

来自于https://github.com/slodge/MvvmCross/blob/vnext/Sample%20-%20CustomerManagement/CustomerManagement/CustomerManagement.Touch/Views/BaseCustomerEditView.cs
请注意,在MvvmCross绑定MonoTouch和MonoDroid时,像文本编辑框这样的默认绑定通常默认情况下是TwoWay
如果您成功运行了一个样例,请随意将其发布到gist或repo上,或者写博客介绍 - 看起来我们需要一些样例来参考!

我一定会研究这个的。只要我让这个例子运行起来,我就会发布我的结果。谢谢! - zleao
似乎有一些东西缺失了...但是现在我已经添加了它们,这个问题看起来已经解决了 :) 请参见提交 https://github.com/slodge/MvvmCross/commit/1e06da6732db1e99eeba5e3b6aa1042796d63f5f 感谢您发现这个缺失的漏洞! - Stuart
我得说谢谢!问题在我开始查看之前就已经解决了... :) 明天早上我会更新我的分支,然后我可以发布一个可工作的示例。 - zleao

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接