我有以下一般用户控件声明:
I've got the following Generic usercontrol declared:
public partial class MessageBase<T> : UserControl
{
protected T myEntry;
public MessageBase()
{
InitializeComponent();
}
public MessageBase(T newEntry)
{
InitializeComponent();
myEntry = newEntry;
}
}
}
不过,编译器不会允许我这样做:
But the compiler won't allow me to do this:
public partial class MessageControl : MessageBase<Post>
{
public MessageControl()
{
InitializeComponent();
}
}
如何创建在C#泛型的用户控制?
How do I create a generic user control in C#?
试试这个
public partial class MessageControl : MessageControlBase
{
public MessageControl()
{
InitializeComponent();
}
}
public class MessageControlBase : MessageBase<Post>
{}
的关键,让设计师的工作是该类的您正在编辑的基类绝不能通用的。
The key to getting the designer to work is that the base class of the class you are editing must not be generic.