@@ -11,25 +11,56 @@ public class ButtonsViewModel : INotifyPropertyChanged
1111 {
1212 private bool _showDismissButton ;
1313 private double _dismissButtonProgress ;
14+ private string _demoRestartCountdownText ;
1415
1516 public ButtonsViewModel ( )
1617 {
1718 var autoStartingActionCountdownStart = DateTime . Now ;
18- DismissComand = new AnotherCommandImplementation ( _ => { } ) ;
19+ var demoRestartCountdownComplete = DateTime . Now ;
20+ var dismissRequested = false ;
21+ DismissComand = new AnotherCommandImplementation ( _ => dismissRequested = true ) ;
1922 ShowDismissButton = true ;
2023
24+ //just some demo code...it's up to you to set up the
25+ //progress on the button as it would be with a progress bar.
26+ //and then hide the button, do whatever action you want to do
2127 new DispatcherTimer (
2228 TimeSpan . FromMilliseconds ( 100 ) ,
2329 DispatcherPriority . Normal ,
2430 new EventHandler ( ( o , e ) =>
2531 {
32+ if ( dismissRequested )
33+ {
34+ ShowDismissButton = false ;
35+ dismissRequested = false ;
36+ demoRestartCountdownComplete = DateTime . Now . AddSeconds ( 3 ) ;
37+ DismissButtonProgress = 0 ;
38+ }
39+
2640 if ( ShowDismissButton )
2741 {
28- var totalDuration = autoStartingActionCountdownStart . AddSeconds ( 20 ) . Ticks - autoStartingActionCountdownStart . Ticks ;
42+ var totalDuration = autoStartingActionCountdownStart . AddSeconds ( 5 ) . Ticks - autoStartingActionCountdownStart . Ticks ;
2943 var currentDuration = DateTime . Now . Ticks - autoStartingActionCountdownStart . Ticks ;
3044 var autoCountdownPercentComplete = 100.0 / totalDuration * currentDuration ;
3145 DismissButtonProgress = autoCountdownPercentComplete ;
46+
47+ if ( DismissButtonProgress >= 100 )
48+ {
49+ demoRestartCountdownComplete = DateTime . Now . AddSeconds ( 3 ) ;
50+ ShowDismissButton = false ;
51+ UpdateDemoRestartCountdownText ( demoRestartCountdownComplete , out _ ) ;
52+ }
3253 }
54+ else
55+ {
56+ UpdateDemoRestartCountdownText ( demoRestartCountdownComplete , out bool isComplete ) ;
57+ if ( isComplete )
58+ {
59+ autoStartingActionCountdownStart = DateTime . Now ;
60+ ShowDismissButton = true ;
61+ }
62+ }
63+
3364 } ) , Dispatcher . CurrentDispatcher ) ;
3465 }
3566
@@ -47,6 +78,20 @@ public double DismissButtonProgress
4778 set { this . MutateVerbose ( ref _dismissButtonProgress , value , RaisePropertyChanged ( ) ) ; }
4879 }
4980
81+ public string DemoRestartCountdownText
82+ {
83+ get { return _demoRestartCountdownText ; }
84+ private set { this . MutateVerbose ( ref _demoRestartCountdownText , value , RaisePropertyChanged ( ) ) ; }
85+ }
86+
87+ private void UpdateDemoRestartCountdownText ( DateTime endTime , out bool isComplete )
88+ {
89+ var span = endTime - DateTime . Now ;
90+ var seconds = Math . Round ( span . TotalSeconds < 0 ? 0 : span . TotalSeconds ) ;
91+ DemoRestartCountdownText = "Demo in " + seconds ;
92+ isComplete = seconds == 0 ;
93+ }
94+
5095 public event PropertyChangedEventHandler PropertyChanged ;
5196
5297 private Action < PropertyChangedEventArgs > RaisePropertyChanged ( )
0 commit comments