1

ビュー定義 (つまり、レイアウト ファイルに表示されるコンテンツ) が json 構造で定義されている状況があります。バインディングと共にこの json 構造を定義できるようにする必要があり、コードは json 構造に基づいてコントロールを動的に作成し、レイアウトを埋めることができる必要があります。

以下のコードを使用して同じことを達成できます。

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
         FirstViewModel firstViewModel = new FirstViewModel()
        {
            Id = 1001,
            FirstName = "Amit",
            MiddleName = string.Empty,
            LastName = "Taparia",
            Race = "Asian",
            IsUSNational = false
        };

        this.ViewModel = firstViewModel as IMvxViewModel;
        var bindings = this.CreateInlineBindingTarget<FirstViewModel>();                    

        this.Root = new RootElement("Main View", null, null).
        {
            new Section("Personal Information")
            {                                        
                new StringElement("Employee#","Enter Employee#").Bind(bindings,vm => vm.Id)
                new EntryElement("FirstName","Enter First Name").Bind(bindings,vm=>vm.FirstName),
                new EntryElement("MiddleName","Enter Middle Name").Bind(bindings, vm=> vm.MiddleName),
                new EntryElement("LastName","Enter Last Name","Amit",null).Bind(bindings, vm => vm.LastName),
                new EntryElement("Race","Enter Race").Bind(bindings,vm => vm.Race),
                new BooleanElement("US National",true,).Bind(bindings, vm => vm.IsUSNational).                
            },               
        };
    }

しかし、json ファイルで定義された構造を使用して同じことができる必要があります。MvvmCross を使用してこのようなことができることは知っていますが、これを行う方法がわかりません。

これらの 3 つのサンプル ソリューションに出くわしました。c) ダイアログの例

いくつかの質問

1) AutoView と MvxDialog の使用の違いは何ですか? それは同じものですか?

2) json ファイルで定義された制御構造を使用する潜在的な制限はありますか。アライメントに関連する問題が 1 つあります。json ファイルで定義されたコントロールの配置を制御することはできません。

3) json ファイルで定義された構造を使用してレンダリング/バインディングを実現する方法は?

あなたの応答を楽しみにしています。

4

1 に答える 1

0

Dialog は、「ダイアログ ボックスを作成し、ユーザー インターフェイス用に多数のデリゲートとコントローラーを作成することなく、テーブルベースの情報を表示するための基盤」を提供します ( https://github.com/migueldeicaza/MonoTouch.Dialogから) 。

AutoViews のアイデアは、主に Dialog の上に構築された自動生成された UI のレイヤーを提供することです。これは、特にプロトタイピングだけでなく、場合によってはアプリの一部のファミリにも適用されます - AutoView を待つ必要がありますか? を参照してください。およびhttp://slodge.blogspot.co.uk/2012/10/cross-platform-views-for-mvvmcross-ideas.html

AutoViews の現在の状態は、Android と iOS で利用可能な初期実装があり、この実装の使用方法を示す小さなサンプルがhttps://github.com/slodge/MvvmCross-Tutorials/tree/masterにあります。 /AutoViewExamples

デモの主な目的は、Autoオブジェクトを使用して ViewModel の UI を記述することです。例:

    private KeyedDescription GetDialogAutoView()
    {
        var auto = new RootAuto(caption: "Some Dialog Info")
        {
            new SectionAuto(header: "Strings")
                {
                    new EntryAuto(caption: "Name", bindingExpression: () => Name),
                    new EntryAuto(caption: "Password", bindingExpression: () => Password) { Password = true },
                },
            new SectionAuto(header: "Booleans")
                {
                    new BooleanAuto(caption: "Is available", bindingExpression: () => IsAvailable),
                    new CheckboxAuto(caption: "Is active", bindingExpression: () => IsActive),
                },
            new SectionAuto(header: "DateTimes")
                {
                    new DateAuto(caption: "Date of Birth", bindingExpression: () => DateOfBirth),
                    new TimeAuto(caption: "When", bindingExpression: () => PreferredContactTime),
                },
            new SectionAuto(header: "Debug Info")
                {
                    new StringAuto(caption: "Name", bindingExpression: () => Name),
                    new StringAuto(caption: "Password", bindingExpression: () => Password),
                    new StringAuto(caption: "Is available", bindingExpression: () => IsAvailable),
                    new StringAuto(caption: "Is active", bindingExpression: () => IsActive),
                    new StringAuto(caption: "Date of Birth", bindingExpression: () => DateOfBirth),
                    new StringAuto(caption: "When", bindingExpression: () => PreferredContactTime),
                },
        };

        return auto.ToElementDescription();
    }

これらのAutoオブジェクトの代わりに、Json 形式の記述が利用可能ですが、これに関するドキュメントは現在あまりありません。いくつかのサンプル ファイルはhttps://github.com/slodge/MvvmCross-Tutorials/blob/master/Sample%20-%20CustomerManagement/CustomerManagement%20-%20AutoViewsにあります。たとえば、https://github.com/slodge/ MvvmCross-Tutorials/blob/master/Sample%20-%20CustomerManagement/CustomerManagement%20-%20AutoViews/CustomerManagement.Droid/Assets/DefaultViews/NewCustomerViewModel/Dialog.json

これらの Json ファイルは非常にリフレクションに基づいており、Dialog クラスの名前とプロパティに基づいて構築されています。


あなたの特定のケースでは、AutoViews Json 形式を使用しないことをお勧めします。

ViewModels が Web からモデルをダウンロードし、ViewModels がこれらの説明から UI を構築する必要がある場合など、より具体的な要件があるようです。

このため、C# POCO で独自のビジネス モデルを記述することから始めることをお勧めします。これらはネットワーク接続を介して (Json.Net などを使用して) 簡単にシリアル化でき、ViewModel と View はそれらを表示する方法を考え出すことができます。

すでに知っているように、Fluent API を使用して mvvmcross でメソッド バインディングを行うことは可能ですか? 必要に応じて、UI をディクショナリまたはその他の「動的」ViewModel 構造にバインドできます。これは、動的フォーム データを表示およびバインドするときに役立つと思います。

この最後の表示ステップの一部として AutoViewsの または Json 部分のいずれかを使用できる可能性がありますがAuto、ダイアログ要素に関してネットワーク転送を行うべきではないと思います - そこのビジネスドメインオブジェクトに固執してください。

于 2013-07-24T11:21:41.280 に答える