How to Raise Event in WP8

343 views Asked by At

How to Raise Event in WP8

As title, in WP8 there is no RaiseEvent() method. So, I can't do something like that. I need to activate an event in code.

Please help me!

2

There are 2 answers

1
Sajeetharan On

Suppose if you want to have a Tap Event,

use += to attach event handler in C#

MyButton.Tap += onTouch;

Events for Windows Phone 8

0
vITs On

You need to use Event-Delegate mechanism of .Net for this do like this:

//Declare Delegate and Event like this:

public delegate void YourDelegate();        
public event YourDelegate YourEvent;

// Fire YourEvent from your code like this:

if (YourEvent!= null)
{
    YourEvent();
}

Say you did this in YourClass.cs then in suppose MainPage.xaml.cs:

YourClass object=new YourClass();       
// Register HttpEvent event
object.YourEvent+= Handler_YourEvent;

add event handler in MainPage.xaml.cs:

void Handler_YourEvent()
{
//code to handle event
}

Hope this Helped you.