如何将列表转换为ObservableCollection?
发布时间:2020-07-16 02:47:04 所属栏目: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 – 为什么模拟会话中定义的DOS设备不会出现在资源管
- Windows – 由于MSVCR110.dll,MS Visual Studio 2012终端无
- WIN10家庭中文版远程提示要求的函数不支持 win10家庭版提示
- wpf – xaml Scrollviewer – 禁用整个窗口的过度滚动/橡皮
- 用于类似Office 2013的Windows的Windows GUI库?
- Windows – 无法从GitBash运行TASKKILL
- Shared Event-loop for Same-Origin Windows(译)
- windows – 如何使批处理文件自行删除?
- 无法加载Microsoft.WindowsAzure.ServiceRuntime,Version =
- windows-phone-8.1 – 如何检测在Windows 10 Mobile上启动的
推荐文章
站长推荐
- 标签为Windows的SSH工具?
- 有没有办法在Windows cli中使用’COPY’命令(Pos
- cmd – 如何为特定应用程序强制传出ip? ForceBi
- Windows Phone 8和Android可以通过Wifi Direct连
- windows – procdump -t – 如何在进程终止时转储
- windows-phone-7 – WIndows Phone 7.1 SDK与Win
- window python2.7 ImportError: No module named
- Windows下的PHP安装pear教程
- NonSerialized 字段如果在dll 中读到数据写入Mon
- 如何将windows自带的简化版OneNote卸载?
热点阅读
