2013-04-10 28 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