用于 MvxItemTemplate 的 MvvmCross 特定 ViewModel 来填充 AutoCompleteTextView

MvvmCross Specific ViewModel for MvxItemTemplate to populate AutoCompleteTextView

我想知道,当您在 xml 中创建 MvxListView 并使用 MvxItemTemplate 来描述项目时,是否有一种方法可以为每一行分配使用的 ViewModel(假设有一个) .我通过扩展我的项目 class 解决了一个类似的问题,但我想让另一个项目成为一个 AutoCompleteTextView,它的提示列表从数据库中填充。我可以将列表放入 IEnumerable,只需将该列表分配给列表中的每个项目即可。我想如果我可以控制为每个项目创建 ViewModel,我可以添加一个包含提示列表的 属性 并绑定它。

我的主要观点是:

<?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-auto"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Mvx.MvxListView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        local:MvxBind="ItemsSource ShipmentInventory.Items"
        local:MvxItemTemplate="@layout/inventoryitemview" />
    <FrameLayout
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/frameLayout2" />
    <EditText
        android:inputType="date"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/editText1" />
</LinearLayout>

项目模板的视图是:

<?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-auto"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <MvxSpinner
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:layout_margin="5dp"
        android:padding="2dp"
        local:MvxBind="ItemsSource TagColors; SelectedItem TagColor"
        android:id="@+id/spinner1" />
    <EditText
        android:layout_width="300dip"
        android:layout_height="wrap_content"
        style="@style/InputEditText"
        local:MvxBind="Text InventoryNumber" />
  <AutoCompleteTextView
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        style="@style/InputEditText"
        local:MvxBind="Text Articles; completionHint HintList" />
</LinearLayout>

我想如果我可以控制 ViewModel 对每个项目的使用,我可以向它添加一个名为 HintList 的 属性。有办法吗?

吉姆

我弄清楚了其中的大部分细微差别,并在

创建了一个示例

https://github.com/JimWilcox3/MvxAutoCompleteTest

简而言之,当您将数据绑定到 MvxItemList 时,每个项目的数据模型中的对象充当该项目的 ViewModel。在我的示例中,我刚刚创建了一个项目列表。如果您正在处理来自 WCF 的数据,则可以使用部分 class 扩展在 WCF 中创建的对象。在该部分 class 中,您可以创建 MvxCommand 和其他您可能想要绑定的东西。希望这对某人有所帮助。