C#动态模板隐式转换从System.EventHandler到System.EventHandler< TEventArgs> 的错误 定义Tick的事件处理程序Windows 8应用程序中DispatcherTimer的事件 但是仍然找不到这种情况的解决方案.谢谢.解决方案尝试:private void onMyStoryBoardCompleted(object sender, object e){ }并使用通用EventHandler<object>订阅:myStoryBoard.Completed += new EventHandler<object>(onMyStoryBoardCompleted);当然,这违反了.NET Framework约定,事件处理程序的第二个参数应为EventArgs的实例(或其派生类).我假设您正在另一个框架上运行,例如Windows 8 Metro,该框架的Timeline类定义了EventHandler<object>签名的.ui.xaml.media.animation.timeline.completed> Completed 事件.I have read already a few threads about this, but I still don't know how to solve it in my case. I come from Java and mostly new to C#I want to attach listener when animation finishes:myStoryBoard.Completed += new EventHandler(onMyStoryBoardCompleted);And:private void onMyStoryBoardCompleted(object sender, EventArgs e){ }And I get the error in the title. I tried: myStoryBoard.Completed += new EventHandler<object>(onMyStoryBoardCompleted);But then I get:no overload for 'onMyStoryBoardCompleted' matches delegate 'System.EventHandler<object>'So it seems that the signature is not compatible with EventHandler<object> and I couldn't find how to make it compatible, I also don't know if this approach is correct.I readUnderstanding events and event handlers in C#C# Dynamic template implicit conversion error from System.EventHandler to System.EventHandler<TEventArgs>defining event handler for Tick event of DispatcherTimer in windows 8 appBut still don't find the solution for this case.Thanks in advance. 解决方案 Try:private void onMyStoryBoardCompleted(object sender, object e){ }And subscribe using the generic EventHandler<object>:myStoryBoard.Completed += new EventHandler<object>(onMyStoryBoardCompleted);Of course, this goes against the .NET Framework convention that the second argument to an event handler should be an instance of EventArgs (or a class derived thereof). I am assuming that you are running on another framework, such as Windows 8 Metro, whose Timeline class defines a Completed event with an EventHandler<object> signature. 这篇关于无法将类型'System.EventHandler'隐式转换为'System.EventHandler&lt; object&gt;'用于情节提要完整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-21 04:41