Post

#PowerPlatformTip 108: 'Double-Click Magic in PowerApps'

#PowerPlatformTip 108: 'Double-Click Magic in PowerApps'

TL;DR: Count the clicks in the button’s OnSelect and start a short Timer on the first click. When the timer ends, OnTimerEnd checks the count: 1 means single click, 2 or more means double click. Then reset the counter and the timer.

Power Apps buttons only know OnSelect, there is no OnDoubleClick. A counter plus a Timer control gives one button two actions, for example a quick preview on a single click and an edit popup on a double click.

💡 Challenge

How can one button run one action on a single click and a different action on a double click, without a second button cluttering the screen?

✅ Solution

Every click raises a counter. The first click also starts a Timer with a short Duration. Clicks that arrive while the timer runs only raise the counter. When the timer ends, OnTimerEnd reads the counter, runs the matching action and resets everything for the next click.

🔧 How It’s Done

1. Add a Timer control (tmrClick) and set its properties:

🔸 Duration: 400 (milliseconds, the double-click window)

🔸 Start: locTimerRun

🔸 AutoStart: false, Repeat: false, Visible: false

2. Count the clicks in the button’s OnSelect:

UpdateContext({locClicks: locClicks + 1});
If(
    locClicks = 1,
    UpdateContext({locTimerRun: true})
)

🔸 Only the first click starts the timer. A second click inside the 400 ms window just raises locClicks to 2.

3. Decide the action in the timer’s OnTimerEnd:

If(
    locClicks >= 2,
    UpdateContext({locShowEdit: true}),     // double click
    UpdateContext({locShowPreview: true})   // single click
);
UpdateContext({locClicks: 0, locTimerRun: false})

🔸 Setting locTimerRun back to false matters: the timer starts again only when Start changes from false to true.

4. Show the popups.

🔸 Set the Visible property of the preview container to locShowPreview and of the edit container to locShowEdit. Their close buttons set the variable back to false.

🎉 Result

One button, two actions. A single click opens the preview after the short timer window, a double click opens the edit popup, and the counter is clean again for the next interaction.

🌟 Key Advantages

🔸 Fewer buttons: two actions on one control keep the screen clean.

🔸 Familiar UX: users know double click from the desktop.

🔸 Adjustable: the double-click window is one property, Duration.

⚠️ Good to Know

🔸 The single-click action always waits until the timer ends, because the app can only know after the window that no second click followed. Keep Duration short (300 to 500 ms), otherwise single clicks feel slow.

🔸 In Power Apps Studio, timers run only in Preview mode. Test the pattern with F5 or in the published app.

🔸 On touch devices a double tap is less common than on desktop. Use the pattern for power-user shortcuts, not for the only way to reach a function.

🎥 Video Tutorial

🛠️ FAQ

1. How does the method distinguish between a single and a double click?

The counter locClicks rises on every click, and only the first click starts the timer. When the timer ends, OnTimerEnd checks the counter: 1 means single click, 2 or more means double click. Then it resets the counter and locTimerRun.

2. Can I adjust the interval used to detect a double click?

Yes. Change the timer’s Duration. Windows uses 500 ms as its default double-click time, 400 ms keeps single clicks a little faster. Larger values make double clicks easier but delay every single click by the same amount.

3. I only need a double-click action. Do I still need the timer?

No. Store the time of the last click and compare it on the next click:

If(
    !IsBlank(locLastClick) &&
    DateDiff(locLastClick, Now(), TimeUnit.Milliseconds) < 400,
    UpdateContext({locShowEdit: true})
);
UpdateContext({locLastClick: Now()})

The action runs immediately on the second click, a single click does nothing.

🔸 How to Implement OnKeyDown/OnKeyPress Behavior in PowerApps Text Input - another way to give controls an event they don’t have out of the box.

🔸 #PowerPlatformTip 78: ‘Efficient Control Reset’ - reset popup state and controls in one place instead of scattering it across controls.

This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy – live Power Platform workshops, free or CHF 49. Join the workshop waitlist to get notified about new dates. For companies that want this implemented for them, see KMUpower – Power Platform consulting & automation for SMEs (DACH).

This post is licensed under CC BY 4.0 by the author.

Microsoft and the Power Platform product names (for example Power Apps, Power Automate, Copilot Studio) are trademarks of the Microsoft group of companies. This is an independent website. It is not operated, sponsored or endorsed by Microsoft.