Revisão #1

Você está revisando uma revisão mais antiga desta página.
Ir para versão atual


Overview

The Timer is used to take actions or change some aspect of the application based on time. 

The controller can be used in many different ways depending on the needs of the organization, in this article we will explore some usage options. 

Adding Timer 

Control is added via the toolbar on the Input tab by selecting Timer.



Default Settings

With the addition of the control, clicking on the start button and stop the progressive counting of the time.  
Like all controls in Power apps, it supports a change of properties and can be used in other controls and objects. 

Adding Button Control

In the first scenario, separate buttons will be used to start and control the timer, in the first screen, two buttons called btnTimerStart and btnTimerReset were added that will be used to start and reset the timer and a timer called tmrManual. 
    

A global variable called varTimerControl will be used to change the timer settings. In the first node of the application click on the three points and access the Run OnStart property


To create the variable, use the function Set , to start the global variable with the value of false
Set (varTimerControl, false)


In btnTimerStart it will be the start and pause control button, in the OnSelect property add the function
If (varTimerControl = true, Set (varTimerControl, false), Set (varTimerControl, true))


To implement the action on the timer, select tmrManual  and add the Start property , change the default value from false to the value of the variable created in Run OnStart. 
varTimerControl


To disable the timer pattern from starting when you click on it, change the DisplayMode property from  Edit to View.


Start the application by selecting the start button, the timer should start and stop. 


In the button  btnTimerReset add the action of resetting the timer, select the OnSelect property and add the function
Reset (tmrManual)


Naming the Buttons

Then, to show users the button functions, change the Text properties


For  btnTimerReset it will be changed to "Reset", 


The btnTimerStart button   has two functions, the start and pause of the timer, we can add an If function to display the texts depending on the action of the button. In the text property
If (varTimerControl = true, Set (varTimerControl, false), Set (varTimerControl, true))

    


Working with Countdown 

Another way of working the timer is in the regressive way, you can duplicate the existing screen and rename the objects of the app Timer to tmrCountdown, the start button btnTimerStartCountdown and the reset button btnTimerResetCountdown


  

To change the behavior of the timer, just change the Text property and use another Timer property called Duration. Click on the tmrCountdown Timer and select the Text property , and add it to the formula. 
Text (Time (0, 0, (tmrCountdown.Duration - Self.Value) / 1000), "[$ -en-US] hh: mm: ss")


With the change the timer controller will be updated with the 00:00:06 marker, which is the default value of the Duration property


One point of attention is that the values ​​are represented in milliseconds, 


The timer can also be used to change the display of other controllers, add a second controller of type Ratting  rtgCountdown


To guarantee the number of stars equal to the total time of the timer, change the Max property to the value
tmrCountdown.Duration / 1000


The goal is to display the passage of seconds and change the number of stars filled, in Default add 
(tmrCountdown.Duration - tmrCountdown.Value) / 1000





When the timer reaches zero, all the watches are off, but the start button does not return to the name of Start.


To correct the button name, we can use a Timer property called OnTimerEnd, select tmrCountdown and change the property to change the control variable to false.
Set (varTimerControl, false)





We can add a text box inside the application to allow the user to modify the timer time, add a Text Input control and configure the name  txtTimerInput. 

To use the value of txtTimerInput  as the duration of the timer, select tmrCountdown  and change the Duration property to use the value entered in the text box.
Value (txtTimerInput.Text) * 1000


Changing the time of the text changes the values ​​in the timer and also the number of stars in the  rtgCountdown


We can still guarantee that users will not be able to add non-numeric characters to the text box. 
For this there is a property that can be used to ensure that the box accepts only numeric values, select the txtTimerInput  and in the Format property configure the option. 
TextFormat.Number


Related articles

Power Platform: PowerApps Controls Survival Guide
: Timer

References

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/controls/control-timer
https://powerusers.microsoft.com/t5/Building-Power-Apps/Configurable-countdown-timer -with-progress-bar / td-p / 130005