无法将类型'System.EventHandler'隐式转换为'System.EventHandler< object>'用于情节提要完整

编程入门 行业动态 更新时间:2024-10-28 02:36:02
本文介绍了无法将类型'System.EventHandler'隐式转换为'System.EventHandler< object>'用于情节提要完整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经阅读了一些有关此的主题,但是我仍然不知道如何解决此问题.我来自Java,大部分是C#的新手

我想在动画结束时附加侦听器:

myStoryBoard.Completed += new EventHandler(onMyStoryBoardCompleted);

并且:

private void onMyStoryBoardCompleted(object sender, EventArgs e) { }

我得到标题中的错误.我试过了:

myStoryBoard.Completed += new EventHandler<object>(onMyStoryBoardCompleted);

但是我得到:

no overload for 'onMyStoryBoardCompleted' matches delegate 'System.EventHandler<object>'

因此,签名似乎与EventHandler <object>不兼容,我找不到如何使其兼容的方式,我也不知道这种方法是否正确.

我读

了解C#中的事件和事件处理程序

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.timelinepleted> 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 read

Understanding 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 app

But 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&a

本文发布于:2023-11-07 06:58:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1565828.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   提要   情节   完整   类型

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!