C# Xamarin.Android MVVMCross上的MvxSpinner绑定问题

C# Xamarin.Android MVVMCross上的MvxSpinner绑定问题,c#,xamarin,mvvmcross,C#,Xamarin,Mvvmcross,将Xamarin.Android与MVVMCross一起使用。从MVXSpinner中选择不绑定到模型中的SelectedYear属性的值时。加载页面时,调试器进入SelectedYear属性,但当我从微调器中选择所需的值时,调试器进入SelectedYear。我没有收到任何错误。请任何人告诉我哪里错了 在输出窗口上发现绑定问题 MvxBind:警告:228.30未能为绑定SelectedYear的SelectedItem创建目标绑定 [0:]MvxBind:警告:228.30未能为绑定Sele

将Xamarin.Android与MVVMCross一起使用。从MVXSpinner中选择不绑定到模型中的
SelectedYear
属性的值时。加载页面时,调试器进入
SelectedYear
属性,但当我从微调器中选择所需的值时,调试器进入
SelectedYear
。我没有收到任何错误。请任何人告诉我哪里错了

在输出窗口上发现绑定问题

MvxBind:警告:228.30未能为绑定SelectedYear的SelectedItem创建目标绑定 [0:]MvxBind:警告:228.30未能为绑定SelectedYear的SelectedItem创建目标绑定 11-09 11:50:03.756 I/mono标准输出(32419):MvxBind:警告:228.30未能为绑定SelectedYear的SelectedItem创建目标绑定

   <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        android:orientation="vertical"
        android:layout_alignParentRight="true"
        android:layout_marginRight="50dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/Retread.Collection.UI.DroidPhone.DotYear"
            style="@style/LabelTextView" />
        <MvxSpinner
            android:id="@+id/txtYear"
            android:layout_width="20dp"
            android:layout_height="wrap_content"
            android:overlapAnchor="false"
            local:MvxItemTemplate="@drawable/year_spinner"
            local:MvxDropDownItemTemplate="@drawable/year_spinnerdropdown"
            android:hint="@string/Retread.Collection.UI.DroidPhone.Year"
            local:MvxBind="ItemsSource Year;SelectedItem SelectedYear"
            style="@style/AppSpinnerStyle" />

也许如果我发布一些对我有用的东西,它可以为你指明正确的方向

微调器:

<Mvx.MvxSpinner
    style="@style/spinner"
    android:background="@drawable/spinner_selector"
    local:MvxItemTemplate="@layout/item_spinner"
    local:MvxBind="ItemsSource Position; SelectedItem SelectedPosition"
    android:id="@+id/positionSpinner" />
回答这里

您需要从调用MVXAPPCompativeSetupHelper.FillTargetFactorys 您的Setup.cs。也许有一种方法我们可以通过这个插件来实现自动化 建筑


你没有弄清楚这里出了什么问题。预期的结果是什么?你看到了什么?为什么错了?预期结果是当我发布表单时,我需要SelectedYear属性中的绑定值(selected value)。但是我在SelectedYear属性中没有得到任何值(null)。我看到的是,当我从下拉列表中选择一个值时,从ViewModel中触发的无事件到SelectedYear属性。我不知道我哪里弄错了。给我们看看你的YearModel代码。虽然这个链接可以回答这个问题,但最好在这里包含答案的基本部分,并提供链接供参考。如果链接页面发生更改,仅链接的答案可能无效。-@maazza不是已经有答案了吗?“您需要从Setup.cs调用MVXAPPCompativeSetupHelper.FillTargetFactorys”
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    style="?android:attr/spinnerDropDownItemStyle"
    android:singleLine="true"
    android:background="#ffffff"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:ellipsize="marquee"
    local:MvxBind="Text DisplayYear" />
 private List<YearModel> _Year;
            public List<YearModel> Year
            {
                get
                {
                    return _Year;
                }
                set
                {
                    _Year = value;
                    RaisePropertyChanged(() => Year);
                }
            }

       public YearModel SelectedYear
        {
            get
            {
                return Model.SelectedYear;
            }
            set
            {
                Model.SelectedYear = value;
                RaisePropertyChanged(() => SelectedYear);
            }
        }
<Mvx.MvxSpinner
    style="@style/spinner"
    android:background="@drawable/spinner_selector"
    local:MvxItemTemplate="@layout/item_spinner"
    local:MvxBind="ItemsSource Position; SelectedItem SelectedPosition"
    android:id="@+id/positionSpinner" />
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    style="@style/Spinner.MyPlayers"
    android:singleLine="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/dummy_title"
    local:MvxBind="Text Caption" />
protected int SelectedPositionId
{
    get { return SelectedPosition == null ? 1 : SelectedPosition.Index; }
}

protected SpinnerItem _selectedPosition;
public virtual SpinnerItem SelectedPosition
{
    get { return _selectedPosition; }
    set 
    { 
        if (_selectedPosition != value)
        {
            _selectedPosition = value;

            SettingsPreferences.SelectedPosition = SelectedPositionId;

            RebuildLists(true);

            RaisePropertyChanged(() => SelectedPosition);
            RaisePropertyChanged(() => DisplayCleanSheets);
            RaisePropertyChanged(() => FilteredPlayers);
        }
    }
}

List<SpinnerItem> _position;
public List<SpinnerItem> Position
{
    get 
    { 
        if (_position != null)
            return _position; 

        _position = new List<SpinnerItem>();

        var values = (int[])Enum.GetValues(typeof(PositionEnumeration));

        foreach (var val in values.Where(p => p > 0))
            _position.Add(new SpinnerItem(val, SharedTextSource.GetText(Enum.GetName(typeof(PositionEnumeration), val))));

        return _position;
    }
}
public class SpinnerItem
{
    public SpinnerItem(int index, string caption, int primaryKeyId = 0, string tag = "")
    {
        Index = index;
        Caption = caption;
        PrimaryKeyId = primaryKeyId;
        Tag = tag;
    }

    public int Index { get; private set; }

    public string Caption { get; private set; }

    public string Tag { get; private set; }

    public int PrimaryKeyId { get; private set; }

    public override string ToString()
    {
        return Caption;
    }

    public override bool Equals(object obj)
    {
        var rhs = obj as SpinnerItem;

        if (rhs == null)
            return false;

        return rhs.Caption == Caption;
    }

    public override int GetHashCode()
    {
        return Caption == null ? 0 : Caption.GetHashCode();
    }
}