locked
ProgressBar in WinRT not showing correct intervals

    Question

  • Hi,

    I have implemented 30 seconds ProgressBar in WinRT application. it works fine but bar is not filling to 100% it starts from 30% and as the 30 seconds goes on it reduces by 1 second and restarts at 30% I want it to be it should starts at 100% and then reduce that amount every second at the end by 30 seconds it should be empty

    Please Help My code is

            private void StartTimer()
            {
                DispatcherTimer MyDispatcherTimer = new DispatcherTimer();
    
                MyDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100);
                MyDispatcherTimer.Tick += new EventHandler<object>(Timer_Tick);
                MyDispatcherTimer.Start();
            }
    
            private void Timer_Tick(object sender, object e)
            {
                 //Some Code
                 UpdateProgressBar();
            }
    
            private void UpdateProgressBar()
            {
                ProgressBar.Value = NumberSecondsLeft();
    
                if (NumberSecondsLeft() <= 5)
                {
                    ProgressBar.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    ProgressBar.Foreground = new SolidColorBrush(Colors.Green);
                }
            }
    
            public static int NumberSecondsLeft()
            {
                TimeSpan TS = DateTime.UtcNow - new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                long CurrentTimeSeconds = (long)Math.Floor(TS.TotalSeconds);
                int SecondsElapsed = (int)CurrentTimeSeconds % 30;
                int SecondsLeft = 30 - SecondsElapsed;
                return SecondsLeft;
            }
    


    • Edited by xSHERU Sunday, July 27, 2014 7:18 PM
    Sunday, July 27, 2014 7:17 PM

Answers

  • I got it working

    Here is the code to update the value of Progress Bar
                int CurrPercent = NumberSecondsLeft();
                double PERCENT = CurrPercent * 100 / IntervalLength;
                xProgressBar.Value = PERCENT;


    • Edited by xSHERU Sunday, July 27, 2014 10:34 PM
    • Marked as answer by xSHERU Sunday, July 27, 2014 10:34 PM
    Sunday, July 27, 2014 10:33 PM

All replies

  • Why won't you do all this animation stuff in Microsoft Blend its really really easy in blend for help please refer to the following article:

    http://www.thenerdmag.com/create-simple-storyboard-app/

    If you found it helpful please purpose it as answer otherwise leave it it might be helpful for others

    Sunday, July 27, 2014 8:20 PM
  • I dont want to create indeterminate Progress bar I want to create determinate progress bar and the working of this progress ba is completely depends on the time and the secret key which will create code using that time so the key and time can be anything at any time... its not going to depend on when i am going to start the app... and I dont think there is a way to do this in Blend

    If there is then tell me


    • Edited by xSHERU Sunday, July 27, 2014 10:10 PM
    Sunday, July 27, 2014 10:09 PM
  • I got it working

    Here is the code to update the value of Progress Bar
                int CurrPercent = NumberSecondsLeft();
                double PERCENT = CurrPercent * 100 / IntervalLength;
                xProgressBar.Value = PERCENT;


    • Edited by xSHERU Sunday, July 27, 2014 10:34 PM
    • Marked as answer by xSHERU Sunday, July 27, 2014 10:34 PM
    Sunday, July 27, 2014 10:33 PM
  • Yes there is you can do any thing in blend you can make custom loaders , progress bars , custom buttons , customs textblocks , etc. everything can be done by blend and its really really easy if you would say i have a custom ring loader project i would share that with you and help you to learn blend you can even bind data using blend

    Please if found helpful purpose it as answer else leave it. thankyou

    Monday, July 28, 2014 8:27 AM
  • That would be great... Please share that sample
    Monday, July 28, 2014 8:42 AM