如何将列表转换为ObservableCollection?
发布时间:2020-07-16 02:48:29 所属栏目:Windows 来源:互联网
导读:我是一个java开发人员,新到C#silverlight。 在这个类中,我想将产品(List)转换为ObservableCollection。 using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq;namespace
|
我是一个java开发人员,新到C#silverlight。
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace WPListBoxImage
{
/**It seems not work,if I just change List<Product> to ObservableCollection<Product>
public class Products : List<Product>
{
public Products()
{
BuildCollection();
}
private const string IMG_PATH = "../Images/";
public ObservableCollection<Product> DataCollection { get; set; }
public ObservableCollection<Product> BuildCollection()
{
DataCollection = new ObservableCollection<Product>();
DataCollection.Add(new Product("Haystack Code Generator for .NET",799,IMG_PATH + "Haystack.jpg"));
DataCollection.Add(new Product("Fundamentals of N-Tier eBook",Convert.ToDecimal(19.95),IMG_PATH + "FundNTier_100.jpg"));
DataCollection.Add(new Product("Fundamentals of ASP.NET Security eBook",IMG_PATH + "FundSecurity_100.jpg"));
DataCollection.Add(new Product("Fundamentals of SQL Server eBook",IMG_PATH + "FundSQL_100.jpg"));
DataCollection.Add(new Product("Fundamentals of VB.NET eBook",IMG_PATH + "FundVBNet_100.jpg"));
DataCollection.Add(new Product("Fundamentals of .NET eBook",IMG_PATH + "FundDotNet_100.jpg"));
DataCollection.Add(new Product("Architecting ASP.NET eBook",IMG_PATH + "ArchASPNET_100.jpg"));
DataCollection.Add(new Product("PDSA .NET Productivity Framework",Convert.ToDecimal(2500),IMG_PATH + "framework.jpg"));
return DataCollection;
}
}
}
我该怎么办来解决?还是需要创建一个新的类? 您的产品类不应该继承任何东西。public class Products 通过Product类的DataCollection属性访问集合中的所有项目。例如, Products myProducts = new Products(); ObservableCollection<Product> myData = myProducts.DataCollection; 它还取决于您如何使用产品。你可以完全不用这个课,然后做一些类似的事情: ObservableCollection<Product> Products = new ObservableCollection<Product>();
Products.Add(new Product("Haystack Code Generator for .NET",IMG_PATH + "Haystack.jpg"));
// etc... (编辑:长春站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- macos – 在Windows上使用Tycho构建的Eclipse RCP应用程序的
- .net – 为什么我无法在2.0.0.0播放器框架中重用1.8.2.2 Pl
- QML 发布时 libeay32.dll错误
- Windows下使用service.bat安装tomcat服务, 启动停止tomcat服
- 使用autohotkey定制windows 10 虚拟桌面的快捷键
- .net – 在桌面下打开和关闭Windows 8触摸键盘tabtip
- 如何在Windows上确定是否安装了C/C++编译器
- windows – 如何使用Win32 API获取多个监视器的显示名称?
- windows下编译mxnet并使用C++训练模型
- New-Object上的Windows RT Powershell(PermissionDenied)
