【问题标题】:MvxSpinner binding to ItemSource property not workingMvxSpinner 绑定到 ItemSource 属性不起作用
【发布时间】:2018-05-29 14:14:48
【问题描述】:

我有一个很简单的sn-p如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/lib/com.myco.app"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="20px">
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="24dp"
        android:layout_marginTop="10dip"
        android:text="@string/planATripLabel"
        android:textColor="#FF9900" />
    <Spinner
        android:id="@+id/spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/planet_prompt" />

  <!--local:MvxBind="ItemsSource Items; " />-->

    <MvxSpinner
        android:id="@+id/spinner1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/planet_prompt"
        local:MvxBind="ItemsSource Items" />
</LinearLayout>

ViewModel 包含以下代码:

 private ObservableCollection<string> _items = new ObservableCollection<string>()
        {
            "One", "Two", "Three"
        };
        public ObservableCollection<string> Items
        {
            get
            {
                return _items;
            }
            set { _items = value; RaisePropertyChanged(() => Items); }
        }

但是,当我运行应用程序时,什么都没有显示。常规微调器确实显示了它的项目,因为我在视图类中拥有从 Xamarin 网站复制的代码,如下所示:

  Spinner spinner = FindViewById<Spinner>(Resource.Id.spinner);

            spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
            var adapter = ArrayAdapter.CreateFromResource(
                this, Resource.Array.planets_array, Android.Resource.Layout.SimpleSpinnerItem);

            adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            spinner.Adapter = adapter;

我错过了什么?

【问题讨论】:

    标签: xamarin mvvmcross mvxspinner


    【解决方案1】:

    我认为您的 local 命名空间没有考虑到 MvxBind

    我会替换

    xmlns:local="http://schemas.android.com/apk/lib/com.myco.app"

    with(我总是这样用,with res-auto)

    xmlns:local="http://schemas.android.com/apk/res-auto"

    如果这不是问题,我会向MvxSpinner 提供自定义MvxItemTemplate 和自定义MvxDropDownItemTemplate,以查看默认设置是否不起作用。并检查Outputwindow 以查看是否显示任何错误。

    如果您需要任何帮助,请告诉我。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-23
    • 1970-01-01
    • 2020-12-22
    • 1970-01-01
    • 2021-09-17
    • 1970-01-01
    • 2012-06-24
    相关资源
    最近更新 更多