-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,265
  • 2
  • 21
  • 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,651
  • 12
  • 30
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
  • 216,225
  • 63
  • 350
  • 396