2013-04-10 91 views
1

我在設計活動時遇到問題。MvxBindableLinearLayout ItemsSource綁定問題

我試圖使用Mvx.MvxBindableLinearLayout,使綁定到列表: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.MvxBind ableListView,我只能看到第一個項目。 目標是滾動所有的元素,而不是列表,作爲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> 

我的困惑表示歉意。

感謝您的幫助和可用性。

+0

更新增加 - 請嘗試在現有樣本中重現您的問題 - 例如在教程 – Stuart 2013-04-11 10:55:11

回答

1

我是保羅·迪亞斯的同事和我們剛剛想出發生了什麼...... 的問題是在創造的MvxBindableLinearLayout

在構造函數中,我們有

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

而在財產「適配器」的「設置」,我們有

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連t被訂閱兩次(在構造函數和適配器屬性集中)。 如果我們有一個綁定到MvxBindableLinearLayout的可通知集合,這可能會成爲問題。

現在棘手的問題......這個錯誤只「顯露自己」當我們在創建UI控件後綁定列表變化(即增加新項目列表)。如果我們在'在構造函數中設置'的viewmodel中有一個列表,然後永遠不會更改,那麼DataSetChanged事件將永遠不會被觸發。另一方面,如果我們在創建用戶界面後添加項目(即可以將命令綁定到按鈕,將項目添加到列表中),項目將在用戶界面中複製...

要解決這個問題,we've只是評論,其中DataSetChanged`是beeing認購在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上提出要求

2

我只是想在v3和這個代碼和預期一樣:

<?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/com.cirrious.dailydilbert" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <Mvx.MvxLinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     local:MvxBind="ItemsSource Items;ItemClick ItemSelectedCommand" 
     local:MvxItemTemplate="@layout/listitem_dilbert" /> 
</ScrollView> 

我真的不能看到的LinearLayout任何問題你已經發布的代碼。如果我可以看到列表項目的模板和視圖模型列表本身,它可能會有所幫助。如果您認爲存在缺陷,那麼請在某處發佈一個簡單的複製,然後我會查看它 - 複製越快,我可以更快地查看它 - 即理想地在github repo上發佈完整解決方案 - 我可以下載然後運行它。

對於可綁定的ListView,我會懷疑屬性android:layout_height="wrap_content" - 懷疑可能無法正常工作。


更新,我也試過在教程的應用程序,與LinearLayout中替換的ListView在Page_MainMenuView.axml

<?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/Tutorial.UI.Droid" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<Mvx.MvxLinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    local:MvxBind="ItemsSource Items;ItemClick ShowItemCommand" 
    local:MvxItemTemplate="@layout/listitem_viewmodel" 
    /> 
</ScrollView> 

這顯示完美 - 做這項工作也是在你的設置?

如果是這樣,那麼問題必須在代碼中的某個地方,你不包括...

+0

的主菜單中,我評論了所有的代碼。 difereça是我使用Mvx.MvxBindableLinearLayout。我的模板只包含一個LinearLayout和一個TextView。我在代碼中什麼也沒做。在Windows Phone 8中一切正常。 – 2013-04-11 11:40:15

+0

對不起 - 我不明白最後一條評論 – Stuart 2013-04-11 11:41:33

+0

我們正在使用vnext。我太困惑,不明白問題的原因。 – 2013-04-11 11:52:08