正如你可以在下面的PIC看到,对于ListView控件,您可以使用属性面板中添加项目。
As you can see in the pic below, for a ListView Control you can add Items using the Properties pane.
我如何使这种东西对我的用户?
How do I enable this kind of stuff for my UserControl?
我没有得到任何东西,当我搜索谷歌,但我可能没有使用正确的术语。
I'm not getting anything when I search Google, but I'm probably not using the correct terms.
有谁知道?
感谢
您需要创建一个定义对象类型的集合IDS组成的一类。一个ListView有ListViewItem的对象。一个的TabControl有TabPage的对象。你控制了这是由您定义的对象。让我们把它叫做MyItemType。
You need to create a class that defines the object type that the collection ids composed of. A listView has ListViewItem objects. A TabControl has TabPage objects. Your control has objects which are defined by you. Let's call it MyItemType.
您还需要一个wraper类的集合。下面的简单实现显示。
You also need a wraper class for the collection. A simple implementation is shown below.
public class MyItemTypeCollection : CollectionBase
{
public MyItemType this[int Index]
{
get
{
return (MyItemType)List[Index];
}
}
public bool Contains(MyItemType itemType)
{
return List.Contains(itemType);
}
public int Add(MyItemType itemType)
{
return List.Add(itemType);
}
public void Remove(MyItemType itemType)
{
List.Remove(itemType);
}
public void Insert(int index, MyItemType itemType)
{
List.Insert(index, itemType);
}
public int IndexOf(MyItemType itemType)
{
return List.IndexOf(itemType);
}
}
最后,您需要为集合添加一个成员变量到您的用户控制和妥善装饰它:
Finally you need to add a member variable for the collection to your user control and decorate it properly:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public MyItemTypeCollection MyItemTypes
{
get { return _myItemTypeCollection; }
}
和你现在有一个简单的界面,使您可以浏览和编辑集合。留下了很多有待改进,但仍然做多,你将不得不学习定制的设计师可以是很难理解和实施。
and you now have a simple interface that allows you to browse and edit the collection. Leaves a lot to be desired still but to do more you will have to learn about custom designers which can be difficult to understand and implement.