【发布时间】:2015-11-08 03:37:56
【问题描述】:
将 Xamarin.Android 与 MVVMCross 结合使用。当从 MVXSpinner 中选择未绑定到模型中的SelectedYear 属性的值时。当加载页面调试器进入SelectedYear 属性时,但是当我从微调器中选择值时,它想要进入SelectedYear。我没有收到任何错误。请任何人告诉我我哪里错了。
在输出窗口中发现绑定问题
MvxBind:Warning:228.30 无法为 SelectedYear 的绑定 SelectedItem 创建目标绑定 [0:] MvxBind:Warning:228.30 无法为 SelectedYear 的绑定 SelectedItem 创建目标绑定 11-09 11:50:03.756 I/mono-stdout(32419): MvxBind:Warning: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" />
Year_spinner.xml 文件如下。
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dip"
android:singleLine="true"
android:textColor="#000000"
local:MvxBind="Text DisplayYear"/>
Year_spinnerdropdown.xml 文件如下。
<?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" />
在视图模型中,我有以下属性。在年份模型中,我有一个属性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);
}
}
【问题讨论】:
-
你没有让自己清楚这里出了什么问题。预期的结果是什么?你看到了什么?为什么错了?
-
预期结果是当我发布表单时,我需要在 SelectedYear 属性中绑定值(选定值)。但是我在 SelectedYear 属性中没有得到任何值(null)。我看到的是当我从下拉列表中选择一个值时没有事件触发到 ViewModel 到 SelectedYear 属性。我不知道我在哪里犯了错误。
-
向我们展示您的 YearModel 代码。