Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.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
访问集合列表中的集合Xamarin xaml_Xamarin_Xamarin.forms - Fatal编程技术网

访问集合列表中的集合Xamarin xaml

访问集合列表中的集合Xamarin xaml,xamarin,xamarin.forms,Xamarin,Xamarin.forms,我正在使用xamarin表单并在集合中使用集合我的问题是,当我使用ViewModel模式时,如何绑定到我的线条 我使用telerik数据网格来完成任务,它可以将任何绑定对象作为其项源。所以我的问题是如何访问我的子列表 至少我正在做ItemsSource=“{Binding Boms}” 当我尝试时,我不能只执行ItemsSource=“{Binding Boms.Lines}”,而只得到空白结果 我的代码隐藏 public class stockscandastore:IScanDataSt

我正在使用xamarin表单并在集合中使用集合我的问题是,当我使用ViewModel模式时,如何绑定到我的线条

我使用telerik数据网格来完成任务,它可以将任何绑定对象作为其项源。所以我的问题是如何访问我的子列表

至少我正在做
ItemsSource=“{Binding Boms}”

当我尝试时,我不能只执行
ItemsSource=“{Binding Boms.Lines}”
,而只得到空白结果


我的代码隐藏

public class stockscandastore:IScanDataStore
{
列出项目;
公共库存ScandaStore()
{ 
bomItems=新列表();
var mockItems=新列表
{
新物料清单{BomId=1,Name=“膝盖作业”,数量=20,作业=10},
新物料清单{BomId=1,Name=“返回操作”,数量=20,操作=10}
,
新物料清单{BomId=1,Name=“Steal Plate”,数量=20,操作=10,
行=新列表(){
新BomDetail{BomId=1,Name=“Screw”,Qty=20},
新BomDetail{BomId=2,Name=“Plate”,数量=10},
新BomDetail{BomId=3,Name=“Screw”,Qty=5}
}
} };
foreach(mockItems中的var项)
{
添加(项目);
}
}
我的代码隐藏我将视图模型设置为

ScanTransViewModel-viewModel;
公共股票转让()
{
初始化组件();
BindingContext=viewModel=new ScanTransViewModel();
}
我的模型是:

公共类物料清单
{
公共长BomId{get;set;}
公共长BOMLineID{get;set;}
公共长StockItemID{get;set;}
公共字符串BomLineType{get;set;}
公共十进制?数量{get;set;}
公共长单位ID{get;set;}
公共十进制?MultipleOfBaseUnit{get;set;}
公共字符串代码{get;set;}
公共字符串名称{get;set;}
公共字符串条形码{get;set;}
公共长ProductGroupID{get;set;}
公共字符串ProductGroupCode{get;set;}
公共十进制操作{get;set;}
公共列表行{get;set;}
公共重写字符串ToString()
{
返回码;
}
}

在您的代码隐藏中,您似乎在InitializeContext()之后设置了BindingContext。因为我没有看到强制更新视图的代码,所以我假设问题是视图初始化为空,然后列表更新时没有视图

在您的情况下,我会尝试为您的代码添加接口。然后像这样更新您的列表-

        protected virtual void NotifyPropertyChanged([CallerMemberName]string propertyName = null)
        {
            if (propertyName != null)
                OnPropertyChanged(propertyName);
        }

        private List<Bom> _bomItems= new List<Bom>();
        public List<IBlePeripheral> BomItems
        {
            get { return _bomItems; }
            set
            {
                _bomItems= value;
                NotifyPropertyChanged();

                IsEmptyList = value.Count < 1;
            }
        }
受保护的虚拟void NotifyPropertyChanged([CallerMemberName]字符串propertyName=null)
{
如果(propertyName!=null)
OnPropertyChanged(propertyName);
}
私有列表_bomItems=新列表();
公开名单
{
获取{return\u bomItems;}
设置
{
_bomItems=值;
NotifyPropertyChanged();
IsEmptyList=值。计数<1;
}
}

在您的代码隐藏中,您似乎在InitializeContext()之后设置了BindingContext。因为我没有看到强制更新视图的代码,所以我假设问题是视图初始化为空,然后列表更新时没有视图

在您的情况下,我会尝试为您的代码添加接口。然后像这样更新您的列表-

        protected virtual void NotifyPropertyChanged([CallerMemberName]string propertyName = null)
        {
            if (propertyName != null)
                OnPropertyChanged(propertyName);
        }

        private List<Bom> _bomItems= new List<Bom>();
        public List<IBlePeripheral> BomItems
        {
            get { return _bomItems; }
            set
            {
                _bomItems= value;
                NotifyPropertyChanged();

                IsEmptyList = value.Count < 1;
            }
        }
受保护的虚拟void NotifyPropertyChanged([CallerMemberName]字符串propertyName=null)
{
如果(propertyName!=null)
OnPropertyChanged(propertyName);
}
私有列表_bomItems=新列表();
公开名单
{
获取{return\u bomItems;}
设置
{
_bomItems=值;
NotifyPropertyChanged();
IsEmptyList=值。计数<1;
}
}

如果ScanTransViewModel是您的VM,那么查看该类的代码是非常相关的如果
Boms.Lines
有数据,当然,您可以绑定子列表,如:
ItemsSource=“{Binding Boms.Lines}”
如果ScanTransViewModel是您的VM,那么查看该类的代码是非常相关的如果
Boms.Lines
有数据,当然,您可以像这样绑定子列表:
ItemsSource=“{Binding Boms.Lines}”