@@ -11,25 +11,56 @@ public class ButtonsViewModel : INotifyPropertyChanged
11
11
{
12
12
private bool _showDismissButton ;
13
13
private double _dismissButtonProgress ;
14
+ private string _demoRestartCountdownText ;
14
15
15
16
public ButtonsViewModel ( )
16
17
{
17
18
var autoStartingActionCountdownStart = DateTime . Now ;
18
- DismissComand = new AnotherCommandImplementation ( _ => { } ) ;
19
+ var demoRestartCountdownComplete = DateTime . Now ;
20
+ var dismissRequested = false ;
21
+ DismissComand = new AnotherCommandImplementation ( _ => dismissRequested = true ) ;
19
22
ShowDismissButton = true ;
20
23
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
21
27
new DispatcherTimer (
22
28
TimeSpan . FromMilliseconds ( 100 ) ,
23
29
DispatcherPriority . Normal ,
24
30
new EventHandler ( ( o , e ) =>
25
31
{
32
+ if ( dismissRequested )
33
+ {
34
+ ShowDismissButton = false ;
35
+ dismissRequested = false ;
36
+ demoRestartCountdownComplete = DateTime . Now . AddSeconds ( 3 ) ;
37
+ DismissButtonProgress = 0 ;
38
+ }
39
+
26
40
if ( ShowDismissButton )
27
41
{
28
- var totalDuration = autoStartingActionCountdownStart . AddSeconds ( 20 ) . Ticks - autoStartingActionCountdownStart . Ticks ;
42
+ var totalDuration = autoStartingActionCountdownStart . AddSeconds ( 5 ) . Ticks - autoStartingActionCountdownStart . Ticks ;
29
43
var currentDuration = DateTime . Now . Ticks - autoStartingActionCountdownStart . Ticks ;
30
44
var autoCountdownPercentComplete = 100.0 / totalDuration * currentDuration ;
31
45
DismissButtonProgress = autoCountdownPercentComplete ;
46
+
47
+ if ( DismissButtonProgress >= 100 )
48
+ {
49
+ demoRestartCountdownComplete = DateTime . Now . AddSeconds ( 3 ) ;
50
+ ShowDismissButton = false ;
51
+ UpdateDemoRestartCountdownText ( demoRestartCountdownComplete , out _ ) ;
52
+ }
32
53
}
54
+ else
55
+ {
56
+ UpdateDemoRestartCountdownText ( demoRestartCountdownComplete , out bool isComplete ) ;
57
+ if ( isComplete )
58
+ {
59
+ autoStartingActionCountdownStart = DateTime . Now ;
60
+ ShowDismissButton = true ;
61
+ }
62
+ }
63
+
33
64
} ) , Dispatcher . CurrentDispatcher ) ;
34
65
}
35
66
@@ -47,6 +78,20 @@ public double DismissButtonProgress
47
78
set { this . MutateVerbose ( ref _dismissButtonProgress , value , RaisePropertyChanged ( ) ) ; }
48
79
}
49
80
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
+
50
95
public event PropertyChangedEventHandler PropertyChanged ;
51
96
52
97
private Action < PropertyChangedEventArgs > RaisePropertyChanged ( )
0 commit comments