1

mvxBindableListViewのオブジェクトのプロパティをMVVMCrossとAndroidにバインドしようとすると問題が発生します。

クラスの構造は次のとおりです。

public class A 
{
    public string MyPropertyA1 { get; set; }
    public int MyPropertyA2 { get; set; }
}
public class B 
{
    public int MyPropertyB1 { get; set; }
    public int MyPropertyB2 { get; set; }
}

public class C
{
    public int MyPropertyC1 { get; set; }
    public A MyPropertyA { get; set; }
    public B MyPropertyB { get; set; }
}

mvxBindableListViewは次のようなものです。

<?xml version="1.0" encoding="utf-8"?>
<Mvx.mvxBindableListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/Android.Client"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="{'ItemsSource':{'Path':'Results'}}"
local:MvxItemTemplate="@layout/detail_viewmodel" />

結果は次のとおりです。publicObservableCollectionResults{get; セットする; }およびdetail_viewmodelは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res/Android.Client"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="6dip"
    android:layout_marginTop="6dip"
    android:textAppearance="?android:attr/textAppearanceLarge"
    local:MvxBind="{'Text':{'Path':'MyPropertyA.MyPropertyA1'}}" />

アプリケーションを実行すると、変数'Results'を含む要素の数を含むmvxBindableListViewが表示されますが、行は空です。

誰が何が起こっているのか知っていますか?ありがとう

4

1 に答える 1

1

チュートリアルアプリケーションを変更して、次のメールを使用してみました。

    public class Thing
    {
        public string Life { get; set; }

        public Thing()
        {
            Life = Guid.NewGuid().ToString();
        }
    }

    public class SimpleEmail
    {
        public Thing MyThing { get; set; }
        public string From { get; set; }    
        public string Header { get; set; }    
        public string Message { get; set; }

        public SimpleEmail()
        {
            MyThing = new Thing();
        }
    }

そして、含めるテンプレート:

<TextView
android:id="@+id/email_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6dip"
android:layout_marginTop="6dip"
android:layout_toRightOf="@id/email_from"
local:MvxBind="{'Text':{'Path':'MyThing.Life'}}"
/>

これは、GUIDの罰金を示しています。

コードを見ると、モデルはINotifyPropertyChangedをサポートしていないため、バインドする前にViewModelプロパティを設定しているのではないでしょうか。

これを修正するために、私は試みるかもしれません:

public class A 
{
    public string MyPropertyA1 { get; set; }
    public int MyPropertyA2 { get; set; }
}
public class B 
{
    public int MyPropertyB1 { get; set; }
    public int MyPropertyB2 { get; set; }
}

public class C
{
    public int MyPropertyC1 { get; set; }
    public A MyPropertyA { get; set; }
    public B MyPropertyB { get; set; }
    public C()
    {
       MyPropertyA = new A() { MyPropertyA1 = "TestValue" };
    }
}

アプリに「TestValue」と表示された場合は、バインディングが機能していることがわかります。

次に、表示されている正しい値を取得する必要がある場合は、次の2つの選択肢があります。

  1. ビューをデータにバインドする前にプロパティを設定します
  2. どういうわけか、バインディングチェーンのどこかでINotifyPropertyChangeイベントを通知して、バインディングが更新する必要があることを認識できるようにします。
于 2012-10-11T06:44:36.490 に答える