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...
}
);
}
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