我正在使用包含MvxSpinner的MvxListView。當我的應用程序運行時,跟蹤顯示的幾個實例:在旋轉的SelectedItem不允許MvxListView與MvxSpinner在第一個項目上顯示空條目
Null值結合當前
我知道一個事實,數據對象上的條目不爲空。下面是有關代碼:用於MvxListView佈局是
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<MvxListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="ItemsSource ShipmentLots.Lots"
local:MvxItemTemplate="@layout/inventorylotview" />
<ImageButton
android:src="@drawable/ic_action_new"
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_gravity="center"
local:MvxBind="Click NewLot_Clicked"
android:id="@+id/btnLotNew" />
</LinearLayout>
用於MvxItemTemplate佈局是如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<MvxSpinner
android:layout_width="130dp"
android:layout_height="match_parent"
android:layout_gravity="center"
style="@style/InputSpinner"
local:MvxItemTemplate="@layout/itemspinner"
local:MvxDropDownItemTemplate="@layout/itemspinnerdropdown"
local:MvxBind="ItemsSource LotColors; SelectedItem LotColor"
android:id="@+id/spinner1" />
<EditText
android:layout_width="150dp"
android:layout_height="wrap_content"
style="@style/InputEditText"
local:MvxBind="Text LotNo" />
<ImageButton
android:src="@drawable/ic_action_delete"
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_gravity="center"
local:MvxBind="Click DeleteClicked"
android:id="@+id/btnLotDelete" />
</LinearLayout>
的InventoryViewModel如下:
public class InventoryViewModel
: MvxViewModel
{
public async void Init(Guid ID)
{
await MPS_Mobile_Driver.Droid.DataModel.ShipmentDataSource.GetShipmentInventory(ID);
ShipmentInventory = ShipmentDataSource.CurrInventory;
Shipment = await MPS_Mobile_Driver.Droid.DataModel.ShipmentDataSource.GetShipment((int)ShipmentInventory.idno, (short)ShipmentInventory.idsub);
ShipmentLots = await MPS_Mobile_Driver.Droid.DataModel.ShipmentDataSource.GetShipmentLotList(Shipment.idno, Shipment.idsub);
}
private Shipment _Shipment;
public Shipment Shipment
{
get { return _Shipment; }
set { _Shipment = value; RaisePropertyChanged(() => Shipment); }
}
private ShipmentInventory _ShipmentInventory;
public ShipmentInventory ShipmentInventory
{
get { return _ShipmentInventory; }
set { _ShipmentInventory = value; RaisePropertyChanged(() => ShipmentInventory); }
}
private ShipmentLotList _ShipmentLots;
public ShipmentLotList ShipmentLots
{
get { return _ShipmentLots; }
set { _ShipmentLots = value; RaisePropertyChanged(() => ShipmentLots); }
}
public IMvxCommand NewLot_Clicked
{
get
{
return new MvxCommand(() => NewLot());
}
}
private void NewLot()
{
ShipmentLot Lot = new ShipmentLot();
Lot.ID = Guid.NewGuid();
Lot.idno = Shipment.idno;
Lot.idsub = Shipment.idsub;
ShipmentLots.Lots.Add(Lot);
}
}
視圖模型對於ShipmentLots包含一個名爲Lots的類型ShipmentLot的可觀察集合。 ShipmentLots類是通過WCF服務創建的。我擴展它如下:
public partial class ShipmentLot
{
private static string[] _LotColors = { "Yellow", "Brown", "White", "Blue", "Orange", "Red", "Green", "Purple" };
public string[] LotColors
{
get { return _LotColors; }
}
public IMvxCommand DeleteClicked
{
get
{
return new MvxCommand(() => DeleteLot());
}
}
private void DeleteLot()
{
MPS_Mobile_Driver.Droid.Views.InventoryView act = (MiscFunctions.CurrActivity as MPS_Mobile_Driver.Droid.Views.InventoryView) ?? null;
if (act != null)
{
act.DeleteLot(this);
}
}
}
這照顧有刪除按鈕的工作和提供MvxSpinner的顏色列表。當我運行該應用程序時,我得到Null值不允許錯誤,並且MvxListView中的第一項在MvxSpinner上顏色不正確。隨後的工作正常。我不確定第一個有什麼不同。任何人對此有任何想法?
感謝, 吉姆
@Stuart你可以看看這個嗎?它應該非常簡單,但是,即使在綁定字段中存在另一個值,微調列表中的第一行上的微調器也會顯示微調列表中的第一個值。 – 2015-03-19 18:25:16
我相信這裏已經回答了這個問題:https://github.com/MvvmCross/MvvmCross/issues/944 – Cheesebaron 2015-03-23 10:45:25