@@ -17,16 +17,12 @@ module FirstWindow =
1717 let! step = State( 1 )
1818
1919 let timer =
20- DispatcherTimer(
21- TimeSpan.FromMilliseconds( 1000. ),
22- DispatcherPriority.Default,
23- ( fun _ _ ->
24- if timerOn.Current then
25- count.Set( count.Current + step.Current))
26- )
20+ DispatcherTimer( Interval = TimeSpan.FromSeconds( 1. ), IsEnabled = timerOn.Current)
2721
2822 ( VStack() {
29- TextBlock( $" %d {count.Current}" ). centerText()
23+ TextBlock( $" %d {count.Current}" )
24+ .centerText()
25+ .onReceive( timer.Tick, ( fun _ -> count.Set( count.Current + step.Current)))
3026
3127 Button( " Increment" , ( fun _ -> count.Set( count.Current + step.Current)))
3228 .centerHorizontal()
@@ -37,12 +33,7 @@ module FirstWindow =
3733 ( HStack() {
3834 TextBlock( " Timer" ). centerVertical()
3935
40- ToggleSwitch(
41- timerOn.Current,
42- fun on ->
43- timerOn.Set( on)
44- if on then timer.Start() else timer.Stop()
45- )
36+ ToggleSwitch( timerOn.Current, ( fun on -> timerOn.Set( on)))
4637
4738 })
4839 .margin( 20. )
@@ -82,16 +73,12 @@ module SecondWindow =
8273 let! step = State( 1 )
8374
8475 let timer =
85- DispatcherTimer(
86- TimeSpan.FromMilliseconds( 1000. ),
87- DispatcherPriority.Default,
88- ( fun _ _ ->
89- if timerOn.Current then
90- count.Set( count.Current + step.Current))
91- )
76+ DispatcherTimer( Interval = TimeSpan.FromSeconds( 1. ), IsEnabled = timerOn.Current)
9277
9378 ( VStack() {
94- TextBlock( $" %d {count.Current}" ). centerText()
79+ TextBlock( $" %d {count.Current}" )
80+ .centerText()
81+ .onReceive( timer.Tick, ( fun _ -> count.Set( count.Current + step.Current)))
9582
9683 Button( " Increment" , ( fun _ -> count.Set( count.Current + step.Current)))
9784 .centerHorizontal()
@@ -102,12 +89,7 @@ module SecondWindow =
10289 ( HStack() {
10390 TextBlock( " Timer" ). centerVertical()
10491
105- ToggleSwitch(
106- timerOn.Current,
107- fun on ->
108- timerOn.Set( on)
109- if on then timer.Start() else timer.Stop()
110- )
92+ ToggleSwitch( timerOn.Current, ( fun on -> timerOn.Set( on)))
11193
11294 })
11395 .margin( 20. )
0 commit comments