1

アクティビティの設計に問題があります。

Mvx.MvxBindableLinearLayout を使用して、リストにバインドしようとしています: A、B、および c;

このバインディングを行うと、結果は次のようになります: A B C C B A

正しいのは: A B C

問題のコードは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:local="http://schemas.android.com/apk/res/m2uMobileSales.Droid"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     >

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:local="http://schemas.android.com/apk/res/m2uMobileSales.Droid"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:showDividers="none"
      android:layout_weight="1">

    <include
        layout="@layout/PageCommon_Titlebar" />

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tableLayout1"
        android:divider="@null"
        android:dividerHeight="0dp"
        android:stretchColumns="1">
      <TableRow
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:id="@+id/tableLayout1"
          android:stretchColumns="1">
        <!--Customer Name-->
        <TextView
            android:id="@+id/CustomerName"
            android:layout_width="fill_parent"
             android:layout_height="wrap_content"
            android:textSize="30dp"
            android:layout_weight="1"
            local:MvxBind="{'Text':{'Path':'Customer.CustDetails.Name','Mode':'OneWay'}}" />
      </TableRow>

      <TableRow>
        <!--Detail Pages android:padding="12dp" -->

        <Mvx.MvxBindableLinearLayout
             android:padding="3dip"
             android:id="@+id/ClienteDetails"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
              android:divider="@null"
              android:dividerHeight="0dp"
              android:orientation="vertical"
              android:cacheColorHint="#00000000"
              android:layout_weight="1"
              local:MvxItemTemplate="@layout/listitem_clientdetailpages"
              local:MvxBind="{'ItemsSource':{'Path':'DetailPageViewModels'}}"/>

        <!--<Mvx.MvxBindableListView
            android:id="@+id/ClienteDetails"
            android:divider="@null"
            android:dividerHeight="0dp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:cacheColorHint="#00000000"
            android:layout_weight="1"
            local:MvxItemTemplate="@layout/listitem_clientdetailpages"
            local:MvxBind="{'ItemsSource':{'Path':'DetailPageViewModels', 'Mode':'OneWay'}}" />-->
      </TableRow>

    </TableLayout>

  </LinearLayout>

</ScrollView>

コメント付きの Mvx.MvxBindableListView を使用すると、最初のアイテムしか表示されません。目的は、android の定義のように、リストではなくすべての要素をスクロールすることです。この問題を克服した後、リスト内にリストを作成します (DetailPageViewModels にはリストを含むいくつかの要素があります)。

ScrollView 内にすべての要素を挿入することを勧める投稿をいくつか見ました。

コメントを試してみました Mvx.MvxBindableLinearLayout、ScrollView、MvxBindableListView はうまくいきました。ScrollView を使用すると、最初の要素しか表示されません。

私の目的は、ページ全体と非要素をスクロールする必要があるため、MvxBindableLinearLayout を使用することです。

listitem_clientdetailpages コード:

<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res/m2uMobileSales.Droid"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:showDividers="none"
    android:layout_weight="1">

  <!--Page Title-->
  <TextView
      android:id="@+id/detailpagetitle"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:textSize="24dp"
       android:padding="3dip"
      local:MvxBind="{'Text':{'Path':'Title','Mode':'OneWay'}}" >
  </TextView>

</LinearLayout>

混乱をお詫び申し上げます。

助けてくれてありがとう。

4

2 に答える 2

1

私は Paulo Dias の同僚で、何が起こっているのかを把握したところです... 問題は、MvxBindableLinearLayout

コンストラクターでは、

 Adapter = new MvxBindableListAdapterWithChangedEvent(context);
 Adapter.DataSetChanged += AdapterOnDataSetChanged;

プロパティ「Adapter」の「Set」には、

var existing = _adapter;
if (existing == value)
    return;

if (existing != null && value != null)
{
    existing.DataSetChanged -= AdapterOnDataSetChanged;
    value.ItemsSource = existing.ItemsSource;
    value.ItemTemplateId = existing.ItemTemplateId;
}

if (value != null)
{
    value.DataSetChanged += AdapterOnDataSetChanged;
}

アダプターが初めて作成されるときに、DataSetChangedイベントは 2 回 (コンストラクターとアダプター プロパティのセットで) サブスクライブされます。にバインドされた通知可能なコレクションがある場合、これは問題になる可能性がありMvxBindableLinearLayoutます。

ここで注意が必要なのが... このバグは、UI コントロールが作成されたにバインドされたリストに変更を加えた場合(つまり、リストに新しい項目を追加した場合) にのみ「姿を現す」だけです。ビューモデルに「コンストラクターで設定」され、変更されないリストがある場合、DataSetChangedイベントは決して発生しません。一方、UI の作成後にアイテムを追加すると (つまり、アイテムをリストに追加するコマンドをボタンにバインドすることができます)、アイテムは UI で複製されます...

これを解決するために、DataSetChanged がサブスクライブされているコンストラクターの行にコメントを付けただけMvxBindableLinearLayoutで、すべてが元の場所に戻ります :)

        public MvxBindableLinearLayout(Context context, IAttributeSet attrs)
            : base(context, attrs)
        {
            var itemTemplateId = MvxBindableListViewHelpers.ReadAttributeValue(context, attrs,
                                                                               MvxAndroidBindingResource.Instance
                                                                                                        .BindableListViewStylableGroupId,
                                                                               MvxAndroidBindingResource.Instance
                                                                                                        .BindableListItemTemplateId);
            Adapter = new MvxBindableListAdapterWithChangedEvent(context);
            Adapter.ItemTemplateId = itemTemplateId;
            //Adapter.DataSetChanged += AdapterOnDataSetChanged;
            this.ChildViewRemoved += OnChildViewRemoved;
        }

これが役立つことを願っています!

ps: なぜ誰も以前にこの問題を抱えていなかったのか疑問に思っています...

ps1: 現在、MvvmCross vNext を使用しています。

ps2: Mvvmcross V3 に変更しましたが、問題が解決しません。Githubでリクエストします

于 2013-04-12T10:53:19.337 に答える