如何将列表转换为ObservableCollection?
发布时间:2020-07-16 02:53:42 所属栏目: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... (编辑:岳阳站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows环境redmine安装及应用
- windows-phone-7 – 如何做这样的事情? (应用程序内的瓷砖
- .net – System.Diagnostics.EventLog – 连接到系统的设备
- windows – dokan sshfs有多稳定?
- xaml – 在开发Windows 8 Store应用程序时处理不同的方向
- .net – 在Win32/COM方法上调用PInvoke时,通常有一个明显的
- 立即镜像/同步文件从Windows到Linux服务器的最佳方式
- 用批处理修复 win10 无法升级的问题
- 在Windows上“无法找到vcvarsall.bat”错误
- Windows下的PHP安装pear教程
推荐文章
站长推荐
- 无法使用for循环从Windows批处理脚本编写html
- windows .bat文件如何递归列出* .mp3类型的所有文
- Windows Server 2016 新功能HCI(超融合基础架构)
- windows-phone-7 – 如何做这样的事情? (应用程
- win7“您可能没有权限使用网络资源”的解决办法
- Windows:忘记本地账户开机密码,但记得住PIN码
- 飞溅屏幕 – 通用窗口10个应用程序的Splash屏幕
- windows – 如何使用Win32 API获取多个监视器的显
- 我们可以在Microsoft Bot Framework(.NET / C#)中
- .net – 在Win32/COM方法上调用PInvoke时,通常有
热点阅读