// Sets the progress bar to null (stopped, not seen), and hides clock icon private void StopTimers() { Logger.record("[StopTimers]: Stopping timer (setting to null)", "SMWidget", "info"); ProgressBackground.BeginAnimation(System.Windows.Controls.ProgressBar.ValueProperty, null); Logger.record("[StopTimers]: Hiding clock icon", "SMWidget", "info"); timeralarm.Visibility = Visibility.Hidden; }
// Sets the progress bar to null (stopped, not seen), and hides clock icon private void StopTimers() { Logger.Record("[StopTimers]: Stopping timer (setting to null)", "SMWidget", "info"); ProgressBackground.BeginAnimation(RangeBase.ValueProperty, null); Logger.Record("[StopTimers]: Hiding clock icon", "SMWidget", "info"); timeralarm.Visibility = Visibility.Hidden; }
private void ProgressGo(int time) // time is received in minutes { Logger.record("[ProgressGo]: Time to end: " + time + " min", "SMWidget", "info"); ProgressBackground.Value = 0; Logger.record("[ProgressGo]: Hiding clock icon", "SMWidget", "info"); timeralarm.Visibility = Visibility.Hidden; StopTimers(); if (time > 0) { currentSession.duration = time * 60; Duration duration = new Duration(TimeSpan.FromSeconds(currentSession.duration)); DoubleAnimation timedAnimation = new DoubleAnimation(100, duration); // Progress Bar Repositioning //// // In order to reposition the timer in a proportional place, we do the following calculation: // The position of the progress bar should be put in the percentage elapsed time from the grand total time, // where the grand total time is the elapsed time until now plus the time that was chosen as the new session end. // Elapsed Time // ------------------------------ == Percentage of time elapsed // Elapsed Time + Additional Time ProgressBackground.Value = 100 * ( ((DateTime.Now - currentSession.startingTime).TotalSeconds) / (((DateTime.Now - currentSession.startingTime).TotalSeconds) + currentSession.duration) ); Logger.record("\t[ProgressGo]: Time calculation. Value: " + ProgressBackground.Value + "; Elapsed: " + (DateTime.Now - currentSession.startingTime).TotalSeconds + "; duration: " + currentSession.duration, "SMWidget", "info"); // In order to reposition the timer at the beginning of the progress bar at every change, one should stop it before restarting; // StopTimers(); // // In order to keep the timer in its place and just speed up or slow down to meet the end at the current time, no // other operation needs to be done. //ProgressBackground.Value = ProgressBackground.Value; // WTF? True = True? That's the best 'no other operation' possible? ProgressBackground.BeginAnimation(System.Windows.Controls.ProgressBar.ValueProperty, timedAnimation); } }