Join our Discord server for community support and discussions Icon description

How to Handle Long Press Gesture in Uno Platform Apps

Long-pressing is a powerful gesture that enables users to access secondary options, shortcuts, or context menus by simply pressing and holding on an element.

Here’s a quick and helpful way to add long press events in your Uno Platform applications offering a simple yet effective way to enhance user interactions. From creating contextual menus and quick access shortcuts to adding interactive elements, the potential applications of long press events are virtually limitless.

Long Press Event in Uno Platform

Let’s create a button in our XAML file as a demonstration. To start, we need to give it a name. For this example, we’ll name it “Longpress”. Then, we’ll create a Right Tapped handler and name it “Blog”. Finally, we’ll add our content so that we can see the button when we execute the code.

				
					<Button 
        Content="Uno Platform"
        x:Name="Longpress"
         RightTapped="Blog"/>
				
			

Void Event Handler

Now, we need to set up a void event handler that will allow the user to implement what actions they want to be performed when the user does a long press. For our example, we will make it so that the button’s background color changes to white.

				
					private void Blog(object sender, RightTappedRoutedEventArgs e)
	{
		Longpress.Background = new SolidColorBrush(Colors.Black);
    }
				
			

Adding the RightTapped event handler is easy and straightforward but key to leveraging the Long Press functionality in the Uno Platform. By employing this approach, we can now start adding long press interactions and enriching user experiences in our Uno applications.

About Uno Platform

For those new to the Uno Platform, it allows for creating pixel-perfect, single-source C# and XAML apps that run natively on Windows, iOS, Android, macOS, Linux and Web via WebAssembly. In addition, it offers Figma integration for design-development handoff and a set of extensions to bootstrap your projects. Uno Platform is free, open-source (Apache 2.0), and available on GitHub.

Next Steps

To upgrade to the latest release of Uno Platform, please update your packages to 4.9 via your Visual Studio NuGet package manager! If you are new to Uno Platform, following our official getting started guide is the best way to get started. (5 min to complete)

Tags:

Uno Platform 5.2 LIVE Webinar – Today at 3 PM EST – Watch