MvxAutoCompleteTextView与2个属性绑定

时间:2017-02-17 11:34:31

标签: android xamarin binding mvvmcross

我目前正在尝试使用MvvmCross制作Xamarin.Android应用程序。

这就是我想要实现的目标:

Multiline autocomplete

这是它背后的原因:

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:layout_marginBottom="8dp">
    <MvvmCross.Binding.Droid.Views.MvxAutoCompleteTextView
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:hint="Klant naam"
       local:MvxBind="Text Klant.Naam; ItemsSource KlantNamen; PartialText CurrentKlantHint; SelectedObject SelectedKlant" />
</android.support.design.widget.TextInputLayout>

我想使用包含姓名和号码的列表

1 个答案:

答案 0 :(得分:2)

您需要为项目模板提供MvxAutoCompleteTextView,以便在建议中显示自定义内容。

<MvvmCross.Binding.Droid.Views.MvxAutoCompleteTextView
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:hint="Klant naam"
       local:MvxItemTemplate="@layout/my_template"
       local:MvxBind="Text Klant.Naam; ItemsSource KlantNamen; PartialText CurrentKlantHint; SelectedObject SelectedKlant" />

my_template内,您可以为每个建议的项目定义自己的布局。将该模板内部的视图绑定到KlantNamen集合中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="match_parent"
    android:layout_height="55dp"
    android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
    android:paddingRight="?android:attr/listPreferredItemPaddingRight"
    android:background="?attr/selectableItemBackground">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:textAppearance="@style/TextAppearance.AppCompat.Title"
        local:MvxBind="Text Name" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="25dp"
        android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
        local:MvxBind="Text Price" />
</LinearLayout>
相关问题