I\'ve got the following Generic usercontrol declared:
public partial class MessageBase : UserControl
{
protected T myEntry;
publ
Try this
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.
For one, althought generic controls are possible under .NET, the Visual Studio designers do not support them, so you're on your own if you want to use them. You'll have to instantiate them yourself in your code and perform layout too.
As for the error you mention, it sounds to me like you're looking in the wrong direction. Perhaps you could write the whole error text here?
The .NET framework supports them, but as Vilx mantions, the designers simply do not - and any of the xml/markup-based platforms (xaml (wpf) or ASP.NET) will not like generics at all. So the best advice is: don't use them.
A common compromise is to have a Type
property (or an object
template-property upon which you call GetType()
), and simply cast etc inside the control. Likewise, such usage will commonly make use of things like Activator.CreateInstance
, and TypeDescriptor
(for metadata lookup etc).
Yes. its possible. See Below link to get an idea.
https://web.archive.org/web/20130603104810/http://www.hackersbasement.com/csharp/post/2009/08/29/Generic-Control-Builder-in-ASPNet.aspx