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
C# 如何将listview中的OberservableCollection列表从api查询项复制到新的listview_C#_Xamarin_Mvvm_Xamarin.forms - Fatal编程技术网

C# 如何将listview中的OberservableCollection列表从api查询项复制到新的listview

C# 如何将listview中的OberservableCollection列表从api查询项复制到新的listview,c#,xamarin,mvvm,xamarin.forms,C#,Xamarin,Mvvm,Xamarin.forms,我无法将数据从一个可观测集合复制到另一个可观测集合。我有一个来自http的api调用GetItemsAsync,它将响应放入一个名为ShipList.cs的模型中。在ShipList.cs中有ShipCatalog[]ships。我用HangarCatalog[]机库创建了第二个模型,名为HangarList.cs。我有一个显示船舶主列表(ShipsList)的页面,我希望用户选择船舶(ShipsList.name绑定到此特定列表视图。我尝试使用.Where()要筛选ShipList以仅匹配所选

我无法将数据从一个可观测集合复制到另一个可观测集合。我有一个来自http的api调用GetItemsAsync,它将响应放入一个名为ShipList.cs的模型中。在ShipList.cs中有ShipCatalog[]ships。我用HangarCatalog[]机库创建了第二个模型,名为HangarList.cs。我有一个显示船舶主列表(ShipsList)的页面,我希望用户选择船舶(ShipsList.name绑定到此特定列表视图。我尝试使用.Where()要筛选ShipList以仅匹配所选项目并将该数据复制到HangarCatalog,我无法使用以下代码将GallogForms.Api.ShipCatalog转换为GallogForms.Api.HangarCatalog。 视图模型


      private ShipCatalog _selectedShip;
       public ShipCatalog SelectedShip
        {
        get {return _selectedShip; }
    set
    {if (_selectedShip != value)
    _selectedShip = value;
    id = _selectedShip.id;
    CopyShipData();


    private async void CopyShipData()
            {
                var _container = Items.Where(s => 
        s.name.FirstOrDefault().ToString() == id.ToString()).ToList();
            foreach (var item in _container.Where(s => 
    s.name.FirstOrDefault().ToString() == id.ToString()).ToList())

              //  var items = await _gallogClient.GetItemsAsync<ShipList>();
             //   foreach (var item in items.ships.Where(s => 
      //  s.name.FirstOrDefault().ToString() == id.ToString()).ToList())
                {
                    Hangars.Clear();
                    Hangars.Add(item);
                }
            }

机库列表完美地反映了发货清单,唯一的例外是它被命名为机库列表,公共机库目录[]机库

最后是填充ShipCatalog[]的查询 AddShipViewModel


      private ShipCatalog _selectedShip;
       public ShipCatalog SelectedShip
        {
        get {return _selectedShip; }
    set
    {if (_selectedShip != value)
    _selectedShip = value;
    id = _selectedShip.id;
    CopyShipData();


    private async void CopyShipData()
            {
                var _container = Items.Where(s => 
        s.name.FirstOrDefault().ToString() == id.ToString()).ToList();
            foreach (var item in _container.Where(s => 
    s.name.FirstOrDefault().ToString() == id.ToString()).ToList())

              //  var items = await _gallogClient.GetItemsAsync<ShipList>();
             //   foreach (var item in items.ships.Where(s => 
      //  s.name.FirstOrDefault().ToString() == id.ToString()).ToList())
                {
                    Hangars.Clear();
                    Hangars.Add(item);
                }
            }



      Items.Clear();
            var items = await _gallogClient.GetItemsAsync<ShipList>();
            foreach (var item in items.ships.ToList())
            {
                Items.Add(item);


      }

Items.Clear();
var items=await_gallogClient.GetItemsAsync();
foreach(items.ships.ToList()中的var项)
{
项目。添加(项目);
}

本身没有错误消息,但我无法构造完成此任务的方法。如果您希望查看整个项目以了解更多我正在进行的工作,

当您在
列表视图中点击或选择一个项目时,事件处理程序的第二个参数将包含对所选/点击项目的引用ust需要将其强制转换为正确的类型。然后您可以根据需要引用其所有属性

private void SuggestedShipView_ItemTapped(object sender, ItemTappedEventArgs e)
{
  // e.Item is the specific item selected
  ShipCatalog ship = (ShipCatalog)e.Item;

  // you can then use this ship object as the data source for your Hangar list/control,
  // and/or add it to another List that is just the items the user has selected

}

当用户从第一个列表中选择一个项目时,您希望在第二个列表中显示哪些数据?名称、制造商、值、scu、值、可飞性和我尚未设计的网格布局中的图像。编辑:如果我以后为什么要创建hangarlist模型,我可能需要点击此列表以查看其在应用程序其他部分中的值。首先,这是sorUI的t在ListView中确实不起作用。第二,听起来您希望第二个控件的数据源只是第一个控件中选择的项。您不需要对数据进行任何复杂的转换或复制。这正是我想要做的,第二个列表视图可能仍然是列表视图,也可能不仍然是列表视图。目前,我是planni在复制shippage.Xaml时显示相同的数据。我不太关心列表视图本身,而是用SuggestedShipList中的选定项目填充机库目录。“用SuggestedShipList中的选定项目填充机库目录”-这意味着您可以从第一个列表中选择多个项目?我感谢您的时间和精力。我是一个十足的白痴,因为我无法理解。因此,我按照您提供的内容进行操作,并将其添加到后面的代码中。private void Suggested ShipView_ItemTapped(object sender,ItemTappedEventArgs e)ShipCtalog ship=(ShipCatalog)e、 项目;hangar.flyable=ship.flyable;hangar.scu=shpi.scu等}我的“myShipsList”listview仍然是空的正如我已经提到的,使用listview来显示单个项目的属性真的是行不通的。我也不明白为什么要按属性复制属性-机库和船舶是不同类型的吗?如果是,为什么?listview建议ShipsView只显示列表名称,这样列表就不会混乱myShipsList wil我也只显示名称,它位于SuggestedShipsView的顶部。这样你就可以看到你添加了一艘卡特彼勒飞船或一艘超级巨星,等等。但是,这都在一个名为AddShipPage的页面上。当你退出该页面时,你就回到了机库页面。我想,既然机库目录是一个可观察的页面,我就可以抓取机库目录并进行普及在AddShip上,显示HangerCatalog的Hangar页面是每个ship的完整值列表。您可以使用绑定指定要显示的复杂对象的哪些属性。您不需要创建只具有某些属性而不具有其他属性的特殊类。我理解这一点。我正在尝试围绕HangarCatalog创建一个全新的绑定,以匹配ShipCatalog,只包含用户选择的船舶。我将整个目录绑定到HangarPage,并根据需要显示HangarCatalog中的项目。因此,HangarCatalog需要每个项目ShipCatalog的船舶数量与填充这些项目的船舶数量不同。
private void SuggestedShipView_ItemTapped(object sender, ItemTappedEventArgs e)
{
  // e.Item is the specific item selected
  ShipCatalog ship = (ShipCatalog)e.Item;

  // you can then use this ship object as the data source for your Hangar list/control,
  // and/or add it to another List that is just the items the user has selected

}