-2

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!

Gaurav Deochakke
  • 2,167
  • 2
  • 20
  • 26

2 Answers2

1

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.

vITs
  • 1,623
  • 12
  • 28
0

Suppose if you want to have a Tap Event,

use += to attach event handler in C#

MyButton.Tap += onTouch;

Events for Windows Phone 8

Sajeetharan
  • 203,447
  • 57
  • 330
  • 376