Tuesday, 1 July 2014

How to get PowerSourceChanged Event in Windows Phone

Here is code to add event listner and used dispatcher to launch it.

Note:-Write this code in .cs file of .xaml file,not in ordinary/view model class file.

init()
{
  DeviceStatus.PowerSourceChanged += DeviceStatus_PowerSourceChanged;
}

 void DeviceStatus_PowerSourceChanged(object sender, EventArgs e)
        {
            DeviceStatus.PowerSourceChanged -= DeviceStatus_PowerSourceChanged;
            this.Dispatcher.BeginInvoke(() =>
            {
                              //Write code here...
            }
          );
        }

No comments:

Post a Comment