MvvmCross Android的对话框编程绑定 [英] MvvmCross Android Dialog bind programmatically

查看:343
本文介绍了MvvmCross Android的对话框编程绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的Andr​​oid.Dialog( Cross.UI )在我的MvvmCross项目。我的第一个方法是使用AutoViews。由于此功能还相当年轻,另类是执行联系,Droid的平台上对话。

I want to use the Android.Dialog (Cross.UI) in my MvvmCross project. My first approach was to use AutoViews. As this feature is still fairly young, the alternative was to implement the dialog in touch and Droid platforms.

现在我只是做这个Droid和我需要的视图模型的属性编程绑定到对话框中的元素。

For now i'm just doing this for Droid and I need to programmatically bind the properties of the ViewModel to the elements of the Dialog.

我的查看和视图模型code是以下内容:

My View and ViewModel code is the following:

    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?")
                        }
                };
        }
    }

视图模型

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

我的目标是有一个双向绑定 EntryElement(姓名:)与物业 ViewModel.Configuration.Name

谁能帮助我?可以这样做?

Can anyone help me with this? Can this be done?

推荐答案

我不知道是否有任何monodroid.dialog mvvmcross样本左右浮动不使用autoviews!

I don't know if there are any monodroid.dialog mvvmcross samples floating around which don't use autoviews!

然而....结合基本syntac应该相同MonoTouch.Dialog - 例如是这样的:

However.... the basic syntac for binding should be the same as MonoTouch.Dialog - e.g. something like:

                            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'}}"),
                                },

从<一个href=\"https://github.com/slodge/MvvmCross/blob/vnext/Sample%20-%20CustomerManagement/CustomerManagement/CustomerManagement.Touch/Views/BaseCustomerEditView.cs\" rel=\"nofollow\">https://github.com/slodge/MvvmCross/blob/vnext/Sample%20-%20CustomerManagement/CustomerManagement/CustomerManagement.Touch/Views/BaseCustomerEditView.cs

请注意,在MvvmCross绑定MonoTouch的和MonoDroid的,默认的东西,如文本编辑框结合一般双向默认

Note that in MvvmCross bindings for MonoTouch and MonoDroid, the default binding for things like text edit boxes is generally TwoWay by default.

如果你得到一个样本运行,那么请随时将其发布到一个要点或回购 - 或在博客上写下了 - !看起来我们可以用一些样品做工作从

If you do get a sample running, then please feel free to post it to a gist or to a repo - or to blog about it - looks like we could do with some samples to work from!

这篇关于MvvmCross Android的对话框编程绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆