Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 带有MvxSpinner的MvxListView在第一项上显示空条目_C#_Android_Xamarin_Mvvmcross_Mvxbind - Fatal编程技术网

C# 带有MvxSpinner的MvxListView在第一项上显示空条目

C# 带有MvxSpinner的MvxListView在第一项上显示空条目,c#,android,xamarin,mvvmcross,mvxbind,C#,Android,Xamarin,Mvvmcross,Mvxbind,我使用的是一个MvxListView,它包含和MvxSpinner。当我的应用程序运行时,跟踪显示以下几个实例: 当前微调器SelectedItem绑定中不允许使用空值 我知道数据对象上的条目不是空的。以下是相关代码:MvxListView的布局如下 <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"

我使用的是一个MvxListView,它包含和MvxSpinner。当我的应用程序运行时,跟踪显示以下几个实例:

当前微调器SelectedItem绑定中不允许使用空值

我知道数据对象上的条目不是空的。以下是相关代码: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>
ShipmentLot的viewmodel包含一个名为Lots的ShipmentLot类型的observablecollection。ShipmentLots的类是从WCF服务创建的。我将其扩展如下:

<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>
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);
    }

}
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);
        }
    }
}
这负责让delete按钮工作并为MvxSpinner提供颜色列表。当我运行应用程序时,我得到了Null值not allowed error,并且MvxListView中的第一项在MvxSpinner上的颜色错误。后面的那些很好用。我不知道第一个有什么不同。有人对此有什么想法吗

谢谢,
Jim

在@Cheesebaron和@Stuart的大量帮助下,我发现如果在MvxItemList内的ItemTemplate中使用MvxSpinner或MvxAutoComplete,那么上面层次结构中的任何内容,包括MvxItemList,都不能使用android:layou_height=“wrap_content”。原因是,如果Android操作系统必须动态地确定物体的高度,它必须不止一次地绘制物体。所有的重画在装订时都会把东西弄糊涂。如果您将所有内容设置为固定高度,则所有内容都可以正常工作。要解决上述问题,上述MvxItemView的标记应为

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
        <MvxListView
            android:layout_width="fill_parent"
            android:layout_height="300dp"
            local:MvxBind="ItemsSource ShipmentLots.Lots"
            local:MvxItemTemplate="@layout/inventorylotview" />
        <ImageButton
            android:src="@drawable/ic_action_new"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_gravity="center"
            local:MvxBind="Click NewLot_Clicked"
            android:id="@+id/btnLotNew" />
    </LinearLayout>

关键似乎是安排标记,这样就不必为了确定屏幕某一部分的高度而预先呈现MvxItemList。如果您想了解更多信息,可以参考以下内容:

我还有一个如何在MvxItemList中执行MvxSpinner的工作示例,位于:


这一步从repo开始,以演示该bug。一旦@Cheesebaron告诉我哪里出了问题,我就纠正了,所以这是一个有效的例子。希望这能对某人有所帮助。

@Stuart你能看看这个吗?它应该非常直接,但是MvxListView第一行的微调器显示微调器列表中的第一个值,即使绑定字段中存在另一个值。我相信这里已经回答了这个问题: