ObservableCollection 实现
我知道我错过了一些明显的东西,但我似乎无法在下面的类中实现 ObservableCollection。 IE 它不会出现在 intellsense 中。有人可以让我知道我缺少什么吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Collections.ObjectModel;
using System.Reflection;
using System.ComponentModel;
namespace MyBTOList
{
public class InventoryListBTO : List<InventoryBTO>
{
/// <summary>
/// Get all inventory records from local database
/// </summary>
/// <returns></returns>
public static InventoryListBTO GetAllInventoryRecords()
{
return GetInventoryListBO(Inventory.GetAllInventoryRecordsDb());
}
}
public class InventoryBTO : INotifyPropertyChanged
{
}
I know I am missing something obvious but I can't seem to implement ObservableCollection in my class below. IE it won't show up in intellsense. Can someone please let me know what I am missing.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Collections.ObjectModel;
using System.Reflection;
using System.ComponentModel;
namespace MyBTOList
{
public class InventoryListBTO : List<InventoryBTO>
{
/// <summary>
/// Get all inventory records from local database
/// </summary>
/// <returns></returns>
public static InventoryListBTO GetAllInventoryRecords()
{
return GetInventoryListBO(Inventory.GetAllInventoryRecordsDb());
}
}
public class InventoryBTO : INotifyPropertyChanged
{
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是 .NET 3.0 或 3.5 SP1 ObservableCollection 位于 WindowsBase.dll 中。在4.0中,它位于System.dll中。
If you are using .NET 3.0 or 3.5 SP1 ObservableCollection is in WindowsBase.dll. In 4.0, it is in System.dll.
ObservableCollection
位于System.Collections.ObjectModel
命名空间中。如果您包含了正确的程序集(默认情况下应该是正确的),那么这应该不是问题。VS Intellisense 中泛型类型的一件事是,在您完全键入泛型参数之前,IDE 不会提示您包含正确的命名空间。
此时,如果您右键单击,则不会出现“解决”上下文菜单。
填写通用参数后:
“解析”上下文菜单将可用,您可以添加
using System.Collections.ObjectModel;
或将ObservableCollection
修改为System.Collections.ObjectModel.ObservableCollection
。也许这就是你所看到的?
ObservableCollection
lives inSystem.Collections.ObjectModel
namespace. If you have included the right assemblies(which should be right by default) then it shouldn't be a problem.One thing with generic types in VS Intellisense is that the IDE won't prompt you to include the right namespace until you fully type the generic arguments.
At this point, if you right click, the Resolve context menu wouldn't be there.
Once you fill in the generic arguments:
Resolve context menu will be available and you can either add
using System.Collections.ObjectModel;
or modifyObservableCollection<int>
toSystem.Collections.ObjectModel.ObservableCollection<int>
.Perhaps that's what you were seeing?