" for full-screen viewing I already read a ...">

It is not possible to implicitly convert the type "System.EventHandler" to "System.EventHandler <object>" for full-screen viewing

I already read a few threads about this, but I still don't know how to solve this in my case. I come from Java and basically new to C #

I want to add a listener when the animation ends:

myStoryBoard.Completed += new EventHandler(onMyStoryBoardCompleted); 

and

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

And I get an error in the name. 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 could not find how to make it compatible, I also do not know if this approach is correct.

I read

Understanding Events and Event Handlers in C #

C # Dynamic pattern of implicit conversion error from System.EventHandler to System.EventHandler <TEventArgs>

Defining a Tick event handler for DispatcherTimer in a Windows 8 application

But still no solution has been found for this case.

Thanks in advance.

+6
source share
1 answer

Try:

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

And subscribe using the generic EventHandler<object> :

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

Of course, this contradicts the .NET Framework convention that the second argument to the event handler must be an instance of EventArgs (or its derivative from the class). I assume that you are working in a different environment, such as Windows 8 Metro, whose Timeline class defines a Completed event with the signature EventHandler<object> .

+8
source

Source: https://habr.com/ru/post/945371/


All Articles