3

MvvmCrossプロジェクトでAndroid.Dialog()を使用したいCross.UI。私の最初のアプローチは、AutoViewsを使用することでした。この機能はまだかなり若いので、代替手段は、タッチおよびドロイドプラットフォームでダイアログを実装することでした。

今のところ、私はDroidに対してこれを行っているだけであり、プログラムでViewModelのプロパティをDialogの要素にバインドする必要があります。

私の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です。

誰かがこれを手伝ってくれますか?これはできますか?

4

1 に答える 1

2

自動ビューを使用しないmonodroid.dialogmvvmcrossサンプルが浮かんでいるかどうかはわかりません。

ただし、バインディングの基本的な構文は、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から


MonoTouchおよびMonoDroidのMvvmCrossバインディングでは、テキスト編集ボックスなどのデフォルトのバインディングは通常TwoWay、デフォルトであることに注意してください。


サンプルを実行している場合は、要点またはリポジトリに投稿するか、ブログに投稿してください。いくつかのサンプルを使用して作業できるようです。

于 2013-01-17T18:21:49.523 に答える