【问题标题】:MvxAutoCompleteTextView binding with 2 Properties具有 2 个属性的 MvxAutoCompleteTextView 绑定
【发布时间】:2017-07-06 22:02:32
【问题描述】:

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

这就是我想要达到的目标:

这是它背后的 axml:

<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>

我想使用一个包含名称和数字的列表

【问题讨论】:

    标签: android xamarin binding mvvmcross


    【解决方案1】:

    您需要为 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-03
      • 2023-04-04
      • 2017-02-24
      • 1970-01-01
      • 2012-04-16
      • 2011-02-19
      • 1970-01-01
      相关资源
      最近更新 更多