I'm trying to manage some event.
I've my main project, written in C#, and I've added another project, written in VB.NET.
In the VB.NET project, I've a class, raising an event:
Public Class newMessageArgs
Inherits EventArgs
Public Property messageCode As String
Public Property appName As String
End Class
Public Class EventRaiser
Event NewMessage As EventHandler
Sub MessageEvent(ByVal typeEvent As String, ByVal messageCode As String, appName As String)
If typeEvent = "newMessage" Then
Dim args As newMessageArgs = New newMessageArgs()
args.appName = appName
args.messageCode = messageCode
RaiseEvent NewMessage(Me, args)
End If
End Sub
End Class
The method raising the event, is called from my VB.NET code, but I have to handle it with my C# code. How can I do it?
This event isn't binded to any xaml element.
CODE UPDATED:
Trying to handle the event:
screenshot: https://i.sstatic.net/dD4uB.jpg
attivazione.EventRaiser raiser = new attivazione.EventRaiser();
raiser.NewMessage += raiser_NewMessage; //error: "no overloads for raiser_NewMessage matches the delegate system.eventhandler", underlining red raiser_NewMessage
private void raiser_NewMessage(object sender, newMessageArgs e)
{
//handle your event here
}
Attivazione is the name of the class in VB.NET that raises the event.
Are you intend something like this?
var raiser = new EventRaiser();
raiser.NewMessage += raiser_NewMessage;
private void raiser_NewMessage(object sender, EventArgs e)
{
//handle your event here
}
But newMessageArgs
class and NewMessage
event should be public in your VB code.
And of course, you should add reference to assembly with your VB code into C# project.