1

I have a generic EventArgs class defined as:

public class GenericEventArgs<T> : EventArgs
{
    public GenericEventArgs(T value)
    {
        Data = value;
    }

    public T Data { get; private set; }
}

If I add an event of type EventHandler<T> to my UserControl, it will only appear in the Designer if I subclass my generic EventArgs type.

// this event will not appear in Designer
public event EventHandler<GenericEventArgs<String>> Event1;

// this event appears in Designer as expected
public event EventHandler<StringEventArgs> Event2;

where StringEventArgs is defined as:

public class StringEventArgs : GenericEventArgs<String>
{
    public StringEventArgs(String value)
        : base(value)
    {
    }
}

I have tried adding the [Browsable(true)] attribute to the event, and marking the EventArgs<T> class as Serializable without success.

What could be causing this, and is there a workaround (other than subclassing) available?

I am using VS2010 and .NET 4.0.

g t
  • 7,287
  • 7
  • 50
  • 85
  • The Winforms designer has very limited support for generics, it started at .NET 1.0. It can handle an EventHandler<> okay but a generic of a generic is too much. You'll have to accommodate it and give up your GenericEventArgs. – Hans Passant Oct 10 '13 at 15:08
  • Thanks, thought this might be the case. Not the end of the world. – g t Oct 10 '13 at 15:23

0 Answers0