Studies show that good grammar leads to more promotions and higher salaries. Write with Grammarly

Retreiving the Remaining time of the Windows Phone 8 device battery programatically using C#

In my previous blog post , i explained How to retreive the Battery Level programatically in Windows Phone 8 ?

In this blog post , i will explain how the Windows Phone developers could retreive the estimated or the remaining time of device battery programatically using C#.

How to retreive the Remaining time of the Windows Phone 8 device battery programatically using C# ?

The Battery class includes the property RemainingDischargeTime which is a read only property that gets the time left for the windows phone device battery to be fully discharged.

Get the access to the Battery instance with the Battery.GetDefault() and then use the property RemainingDischargeTime to retreive the time left.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace PhoneApp3
    public partial class MainPage : PhoneApplicationPage
        // Constructor
        public MainPage()
            // SK - To display the Remaining time



Note that when you use the the RemainingDischargeTime , it will show you a invalid remaining time but should work fine on the windows phone device.