【问题标题】:MvvmCross : dynamic item template selection for MvxListViewMvvmCross : MvxListView 的动态项目模板选择
【发布时间】:2013-07-18 04:04:20
【问题描述】:

如果我有一个具有以下 MvxListView 定义的视图:

<Mvx.MvxListView
    android:layout_marginTop="10px"
    android:textFilterEnabled="true"
    android:choiceMode="singleChoice"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:textSize="20dp"
    local:MvxBind="ItemsSource Data; ItemClick LaunchCapabilityViewCmd"
    local:MvxItemTemplate="@layout/itemtemplate1" />

除了将 MvxItemTemplate 硬编码为 itemtemplate1,是否可以根据我想在此视图中显示的数据类型动态设置它?我正在寻找与 WPF 的 DateTemplateSelector 类似的功能。

TIA。

【问题讨论】:

    标签: android-layout xamarin mvvmcross itemtemplate itemtemplateselector


    【解决方案1】:

    您必须使用自定义适配器来执行此操作。

    一些示例展示了如何使用细胞类型选择。见:

    例如来自PolymorphicListItemTypesView.cs

            protected override View GetBindableView(View convertView, object source, int templateId)
            {
                if (source is Kitten)
                    templateId = Resource.Layout.ListItem_Kitten;
                else if (source is Dog)
                    templateId = Resource.Layout.ListItem_Dog;
    
                return base.GetBindableView(convertView, source, templateId);
            }
    

    对于 Android,还有一个优化应该添加到现有的多态适配器示例中 - 包括使用 GetItemViewType 以更好地重用 convertView - 请参阅 https://github.com/slodge/MvvmCross/issues/333

    此问题链接到:

    【讨论】:

    • 我检查了示例,其中包含优化。所以你可以关闭问题:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-09
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多