Skip to content

Instantly share code, notes, and snippets.

@emoacht
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emoacht/4bfe097ca008779adcfe to your computer and use it in GitHub Desktop.
Save emoacht/4bfe097ca008779adcfe to your computer and use it in GitHub Desktop.
Check battery status.
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