Last active
December 12, 2024 22:13
-
-
Save mhrastegari/e9489414ee0129a4d405ef6ffe587db5 to your computer and use it in GitHub Desktop.
Long press sample for Blazor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div style=" | |
width: 150px; | |
height: 150px; | |
display: grid; | |
align-content: center; | |
justify-content: center; | |
border: 2px solid dodgerblue;" | |
@onpointerdown="PointerDown" | |
@onpointerup="PointerUp"> | |
@Text | |
</div> | |
@code { | |
private string Text; | |
private DateTime PointerDownTime; | |
public void PointerDown() | |
{ | |
PointerDownTime = DateTime.UtcNow; | |
Text = "Pointer down"; | |
} | |
public void PointerUp() | |
{ | |
var downTime = (DateTime.UtcNow.Ticks - PointerDownTime.Ticks) / TimeSpan.TicksPerMillisecond; | |
if (downTime > 400) | |
{ | |
Text = "Long press"; | |
} | |
else | |
{ | |
Text = "Short press"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment