Last active
August 29, 2015 14:13
-
-
Save emoacht/4bfe097ca008779adcfe to your computer and use it in GitHub Desktop.
Check battery status.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ComponentModel; | |
using System.Runtime.CompilerServices; | |
using System.Windows.Forms; | |
public class BatteryStatus : INotifyPropertyChanged | |
{ | |
public BatteryChargeStatus BatteryChargeStatus => SystemInformation.PowerStatus.BatteryChargeStatus; // Flag | |
public int BatteryFullLifetime => SystemInformation.PowerStatus.BatteryFullLifetime; | |
public float BatteryLifePercent => SystemInformation.PowerStatus.BatteryLifePercent; | |
public int BatteryLifeRemaining => SystemInformation.PowerStatus.BatteryLifeRemaining; | |
public PowerLineStatus PowerLineStatus => SystemInformation.PowerStatus.PowerLineStatus; | |
public bool BatteryIsCharging => BatteryChargeStatus.HasFlag(BatteryChargeStatus.Charging); | |
internal void Update() | |
{ | |
RaisePropertyChanged(nameof(BatteryChargeStatus)); | |
RaisePropertyChanged(nameof(BatteryFullLifetime)); | |
RaisePropertyChanged(nameof(BatteryLifePercent)); | |
RaisePropertyChanged(nameof(BatteryLifeRemaining)); | |
RaisePropertyChanged(nameof(PowerLineStatus)); | |
RaisePropertyChanged(nameof(BatteryIsCharging)); | |
} | |
#region INotifyPropertyChanged | |
public event PropertyChangedEventHandler PropertyChanged; | |
private void RaisePropertyChanged([CallerMemberName] string propertyName = null) | |
{ | |
var handler = PropertyChanged; | |
if (handler != null) | |
handler(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment