事件使用通用的EventHandler<>在Designer中不可见 [英] Event using generic EventHandler<> not visible in Designer
本文介绍了事件使用通用的EventHandler<>在Designer中不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public event EventHandler< TEventArgs< int>> EventNotVisibleInDesigner;
public event EventHandler EventVisibleInDesigner;
不是特别令人担忧,但是这个设计/正常,还是我做错了? / p>
解决方案
Windows窗体设计器对泛型类型的支持有限。当您避免 EventHandler< T>
的通用类型参数时,它可以正常工作:
public class TEventArgs< T> :EventArgs {}
public class MyEventArgs:TEventArgs< int> {}
public event EventHandler< MyEventArgs> EventNowAlsoVisibleInDesigner;
I've just noticed that if I add an event using a generic eventhandler to my UserControl, the event is not visible in the designer when I add the user control to a form.
public event EventHandler<TEventArgs<int>> EventNotVisibleInDesigner;
public event EventHandler EventVisibleInDesigner;
Not particularly worrisome, but is this by-design/normal, or am I doing something wrong?
解决方案
The Windows Forms designer has limited support for generic types. It will work okay when you avoid the generic type argument for EventHandler<T>
:
public class TEventArgs<T> : EventArgs { }
public class MyEventArgs : TEventArgs<int> { }
public event EventHandler<MyEventArgs> EventNowAlsoVisibleInDesigner;
这篇关于事件使用通用的EventHandler<>在Designer中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文