diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture.sln b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture.sln new file mode 100644 index 000000000..d44a67e64 --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture.sln @@ -0,0 +1,26 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.0.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LongPressGesture", "LongPressGesture\LongPressGesture.csproj", "{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Release|Any CPU.Build.0 = Release|Any CPU + {A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Release|Any CPU.Deploy.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B2C3D4E5-F6A7-8901-BCDE-F23456789012} + EndGlobalSection +EndGlobal diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/App.xaml b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/App.xaml new file mode 100644 index 000000000..a8ff51d35 --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/App.xaml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/App.xaml.cs b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/App.xaml.cs new file mode 100644 index 000000000..c5ce0b0fe --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/App.xaml.cs @@ -0,0 +1,17 @@ +namespace LongPressGesture; + +public partial class App : Application +{ + public App() + { + InitializeComponent(); + } + + protected override Window CreateWindow(IActivationState? activationState) + { + return new Window(new MainPage()) + { + Title = "Long Press Gesture Demo - .NET MAUI" + }; + } +} diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/GlobalUsings.cs b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/GlobalUsings.cs new file mode 100644 index 000000000..e78d112ed --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/GlobalUsings.cs @@ -0,0 +1,3 @@ +global using Microsoft.Maui.Controls; +global using Microsoft.Maui.Controls.Xaml; +global using Microsoft.Maui.Controls.Shapes; diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/LongPressGesture.csproj b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/LongPressGesture.csproj new file mode 100644 index 000000000..472af6053 --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/LongPressGesture.csproj @@ -0,0 +1,59 @@ + + + + net11.0-android;net11.0-ios;net11.0-maccatalyst + $(TargetFrameworks);net11.0-windows10.0.19041.0 + + Exe + LongPressGesture + true + true + enable + enable + + true + + + LongPressGesture + + + com.companyname.longpressgesture + + + 1.0 + 1 + + None + + 15.0 + 17.0 + 23.0 + 10.0.17763.0 + 10.0.17763.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/MainPage.xaml b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/MainPage.xaml new file mode 100644 index 000000000..6489ab54d --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/MainPage.xaml @@ -0,0 +1,181 @@ + + + + + + + + + + + diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/MainPage.xaml.cs b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/MainPage.xaml.cs new file mode 100644 index 000000000..95def8bf2 --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/MainPage.xaml.cs @@ -0,0 +1,83 @@ +using LongPressGesture.ViewModels; + +namespace LongPressGesture; + +public partial class MainPage : ContentPage +{ + public MainPage() + { + InitializeComponent(); + BindingContext = new LongPressViewModel(); + + // Demo 2 (two-finger long press) is iOS/Mac Catalyst only + if (DeviceInfo.Platform == DevicePlatform.Android || + DeviceInfo.Platform == DevicePlatform.WinUI) + { + MultiTouchSection.IsVisible = false; + } + } + + void OnBoxTapped(object? sender, TappedEventArgs e) + { + if (BindingContext is LongPressViewModel vm) + { + vm.OnBoxTapped(); + } + } + + // + void OnLongPressed(object? sender, LongPressedEventArgs e) + { + if (BindingContext is LongPressViewModel vm) + { + var position = e.GetPosition(InteractiveBox); + vm.PositionText = position.HasValue + ? $"Position: ({position.Value.X:F0}, {position.Value.Y:F0})" + : "Position: unavailable"; + } + } + // + + // + void OnLongPressing(object? sender, LongPressingEventArgs e) + { + if (BindingContext is LongPressViewModel vm) + { + vm.LongPressState = e.Status switch + { + GestureStatus.Started => "Status: Started — hold steady...", + GestureStatus.Running => "Status: Running — still holding...", + GestureStatus.Completed => "Status: Completed — gesture complete!", + GestureStatus.Canceled => "Status: Canceled — gesture aborted", + _ => $"Status: {e.Status}" + }; + + var position = e.GetPosition(InteractiveBox); + if (position.HasValue) + vm.PositionText = $"Position: ({position.Value.X:F0}, {position.Value.Y:F0})"; + } + } + // + + void OnMultiTouchLongPressed(object? sender, LongPressedEventArgs e) + { + MultiTouchStatus.Text = "Two-finger long press detected!"; + MultiTouchBox.Color = Colors.Orange; + } + + async void OnImageTapped(object? sender, TappedEventArgs e) + { + await DisplayAlertAsync("Tap Detected", "You tapped the .NET bot!", "OK"); + } + + void OnImageLongPressed(object? sender, LongPressedEventArgs e) + { + if (BindingContext is LongPressViewModel vm) + { + var position = e.GetPosition(sender as Element); + vm.ImageStatus = position.HasValue + ? $"✅ Long pressed at ({position.Value.X:F0}, {position.Value.Y:F0})" + : "✅ Long press detected!"; + } + } +} diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/MauiProgram.cs b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/MauiProgram.cs new file mode 100644 index 000000000..de3cf5320 --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/MauiProgram.cs @@ -0,0 +1,24 @@ +using Microsoft.Extensions.Logging; + +namespace LongPressGesture; + +public static class MauiProgram +{ + public static MauiApp CreateMauiApp() + { + var builder = MauiApp.CreateBuilder(); + builder + .UseMauiApp() + .ConfigureFonts(fonts => + { + fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); + fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); + }); + +#if DEBUG + builder.Logging.AddDebug(); +#endif + + return builder.Build(); + } +} diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Android/AndroidManifest.xml b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Android/AndroidManifest.xml new file mode 100644 index 000000000..e44369870 --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Android/AndroidManifest.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Android/MainActivity.cs b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Android/MainActivity.cs new file mode 100644 index 000000000..480df4c95 --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Android/MainActivity.cs @@ -0,0 +1,11 @@ +using Android.App; +using Android.Content.PM; +using Android.OS; + +namespace LongPressGesture +{ + [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] + public class MainActivity : MauiAppCompatActivity + { + } +} diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Android/MainApplication.cs b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Android/MainApplication.cs new file mode 100644 index 000000000..1d1d90372 --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Android/MainApplication.cs @@ -0,0 +1,16 @@ +using Android.App; +using Android.Runtime; + +namespace LongPressGesture +{ + [Application] + public class MainApplication : MauiApplication + { + public MainApplication(IntPtr handle, JniHandleOwnership ownership) + : base(handle, ownership) + { + } + + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + } +} diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Android/Resources/values/colors.xml b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Android/Resources/values/colors.xml new file mode 100644 index 000000000..fbaa64a5a --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Android/Resources/values/colors.xml @@ -0,0 +1,6 @@ + + + #512BD4 + #2B0B98 + #2B0B98 + diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/MacCatalyst/AppDelegate.cs b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/MacCatalyst/AppDelegate.cs new file mode 100644 index 000000000..4610a5bac --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/MacCatalyst/AppDelegate.cs @@ -0,0 +1,10 @@ +using Foundation; + +namespace LongPressGesture +{ + [Register("AppDelegate")] + public class AppDelegate : MauiUIApplicationDelegate + { + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + } +} diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/MacCatalyst/Entitlements.plist b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/MacCatalyst/Entitlements.plist new file mode 100644 index 000000000..49bfebf36 --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/MacCatalyst/Entitlements.plist @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.network.client + + + diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/MacCatalyst/Info.plist b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/MacCatalyst/Info.plist new file mode 100644 index 000000000..79a863bb8 --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/MacCatalyst/Info.plist @@ -0,0 +1,29 @@ + + + + + UIDeviceFamily + + 2 + + UIRequiredDeviceCapabilities + + arm64 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + XSAppIconAssets + Assets.xcassets/appicon.appiconset + + diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/MacCatalyst/Program.cs b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/MacCatalyst/Program.cs new file mode 100644 index 000000000..bfc0af5ac --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/MacCatalyst/Program.cs @@ -0,0 +1,13 @@ +using ObjCRuntime; +using UIKit; + +namespace LongPressGesture +{ + public class Program + { + static void Main(string[] args) + { + UIApplication.Main(args, null, typeof(AppDelegate)); + } + } +} diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Windows/App.xaml b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Windows/App.xaml new file mode 100644 index 000000000..c0ca9a2a4 --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Windows/App.xaml @@ -0,0 +1,8 @@ + + + diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Windows/App.xaml.cs b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Windows/App.xaml.cs new file mode 100644 index 000000000..ae3b9acb2 --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Windows/App.xaml.cs @@ -0,0 +1,24 @@ +using Microsoft.UI.Xaml; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace LongPressGesture.WinUI; + +/// +/// Provides application-specific behavior to supplement the default Application class. +/// +public partial class App : MauiWinUIApplication +{ + /// + /// Initializes the singleton application object. This is the first line of authored code + /// executed, and as such is the logical equivalent of main() or WinMain(). + /// + public App() + { + this.InitializeComponent(); + } + + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); +} + diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Windows/Package.appxmanifest b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Windows/Package.appxmanifest new file mode 100644 index 000000000..2bcb11edf --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Windows/Package.appxmanifest @@ -0,0 +1,43 @@ + + + + + + + $placeholder$ + User Name + $placeholder$.png + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Windows/app.manifest b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Windows/app.manifest new file mode 100644 index 000000000..a9848fa26 --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/Windows/app.manifest @@ -0,0 +1,15 @@ + + + + + + + + true/PM + PerMonitorV2, PerMonitor + + + diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/iOS/AppDelegate.cs b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/iOS/AppDelegate.cs new file mode 100644 index 000000000..4610a5bac --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/iOS/AppDelegate.cs @@ -0,0 +1,10 @@ +using Foundation; + +namespace LongPressGesture +{ + [Register("AppDelegate")] + public class AppDelegate : MauiUIApplicationDelegate + { + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + } +} diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/iOS/Info.plist b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/iOS/Info.plist new file mode 100644 index 000000000..0004a4fde --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/iOS/Info.plist @@ -0,0 +1,32 @@ + + + + + LSRequiresIPhoneOS + + UIDeviceFamily + + 1 + 2 + + UIRequiredDeviceCapabilities + + arm64 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + XSAppIconAssets + Assets.xcassets/appicon.appiconset + + diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/iOS/Program.cs b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/iOS/Program.cs new file mode 100644 index 000000000..bfc0af5ac --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/iOS/Program.cs @@ -0,0 +1,13 @@ +using ObjCRuntime; +using UIKit; + +namespace LongPressGesture +{ + public class Program + { + static void Main(string[] args) + { + UIApplication.Main(args, null, typeof(AppDelegate)); + } + } +} diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/iOS/Resources/PrivacyInfo.xcprivacy b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/iOS/Resources/PrivacyInfo.xcprivacy new file mode 100644 index 000000000..24ab3b433 --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Platforms/iOS/Resources/PrivacyInfo.xcprivacy @@ -0,0 +1,51 @@ + + + + + + NSPrivacyAccessedAPITypes + + + NSPrivacyAccessedAPIType + NSPrivacyAccessedAPICategoryFileTimestamp + NSPrivacyAccessedAPITypeReasons + + C617.1 + + + + NSPrivacyAccessedAPIType + NSPrivacyAccessedAPICategorySystemBootTime + NSPrivacyAccessedAPITypeReasons + + 35F9.1 + + + + NSPrivacyAccessedAPIType + NSPrivacyAccessedAPICategoryDiskSpace + NSPrivacyAccessedAPITypeReasons + + E174.1 + + + + + + diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/AppIcon/appicon.svg b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/AppIcon/appicon.svg new file mode 100644 index 000000000..9d63b6513 --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/AppIcon/appicon.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/AppIcon/appiconfg.svg b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/AppIcon/appiconfg.svg new file mode 100644 index 000000000..21dfb25f1 --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/AppIcon/appiconfg.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/Fonts/OpenSans-Regular.ttf b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/Fonts/OpenSans-Regular.ttf new file mode 100644 index 000000000..33b3e0d97 Binary files /dev/null and b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/Fonts/OpenSans-Regular.ttf differ diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/Fonts/OpenSans-Semibold.ttf b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/Fonts/OpenSans-Semibold.ttf new file mode 100644 index 000000000..a1f85711f Binary files /dev/null and b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/Fonts/OpenSans-Semibold.ttf differ diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/Images/dotnet_bot.png b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/Images/dotnet_bot.png new file mode 100644 index 000000000..1d1b981ee Binary files /dev/null and b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/Images/dotnet_bot.png differ diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/Splash/splash.svg b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/Splash/splash.svg new file mode 100644 index 000000000..21dfb25f1 --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/Splash/splash.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/Styles/Colors.xaml b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/Styles/Colors.xaml new file mode 100644 index 000000000..30307a5dd --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/Styles/Colors.xaml @@ -0,0 +1,45 @@ + + + + + + + #512BD4 + #ac99ea + #242424 + #DFD8F7 + #9880e5 + #2B0B98 + + White + Black + #D600AA + #190649 + #1f1f1f + + #E1E1E1 + #C8C8C8 + #ACACAC + #919191 + #6E6E6E + #404040 + #212121 + #141414 + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/Styles/Styles.xaml b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/Styles/Styles.xaml new file mode 100644 index 000000000..86f574d8c --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/Resources/Styles/Styles.xaml @@ -0,0 +1,451 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/ViewModels/LongPressViewModel.cs b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/ViewModels/LongPressViewModel.cs new file mode 100644 index 000000000..24615a65b --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/LongPressGesture/ViewModels/LongPressViewModel.cs @@ -0,0 +1,53 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; + +namespace LongPressGesture.ViewModels; + +// +public partial class LongPressViewModel : ObservableObject +{ + [ObservableProperty] + string gestureStatus = "Waiting for long press..."; + + [ObservableProperty] + string positionText = string.Empty; + + [ObservableProperty] + Color boxColor = Colors.MediumPurple; + + [ObservableProperty] + string longPressState = string.Empty; + + [ObservableProperty] + string imageStatus = "Tap or long press the image"; + + // + [RelayCommand] + void LongPress(string source) + { + GestureStatus = $"✅ Long press completed on {source}!"; + BoxColor = GetRandomColor(); + } + // + + [RelayCommand] + void Tap(string source) + { + ImageStatus = $"Tapped on {source}!"; + } + + public void OnBoxTapped() + { + GestureStatus = "👆 That was a tap, not a long press. Hold longer!"; + } + + static Color GetRandomColor() + { + var random = new Random(); + return Color.FromRgb( + random.Next(80, 220), + random.Next(80, 220), + random.Next(80, 220)); + } +} +// diff --git a/11.0/UserInterface/Gestures/LongPressGesture/README.md b/11.0/UserInterface/Gestures/LongPressGesture/README.md new file mode 100644 index 000000000..017c9d81c --- /dev/null +++ b/11.0/UserInterface/Gestures/LongPressGesture/README.md @@ -0,0 +1,51 @@ +--- +name: .NET MAUI - LongPressGesture +description: "This sample demonstrates using the LongPressGestureRecognizer class to implement long press gesture recognition in .NET MAUI 11." +page_type: sample +languages: +- csharp +- xaml +products: +- dotnet-maui +urlFragment: gestures-longpressgesture +--- +# LongPressGesture + +This sample demonstrates the `LongPressGestureRecognizer` introduced in .NET MAUI 11 ([dotnet/maui#33432](https://github.com/dotnet/maui/pull/33432)). + +## Features demonstrated + +- **Long press with Command binding** — A `BoxView` that changes color when the user presses and holds for a configurable duration. +- **MinimumPressDuration** — Custom hold duration (750 ms in this sample). +- **AllowableMovement** — Movement threshold that cancels the gesture if exceeded. +- **NumberOfTouchesRequired** — Requiring two fingers for a long press (iOS / Mac Catalyst only). +- **State tracking** — Real-time feedback via the `LongPressing` event and `GestureStatus` (`Started`, `Running`, `Completed`, `Canceled`). +- **Position detection** — Using `GetPosition()` to report where the gesture occurred. +- **Gesture coexistence** — Combining `TapGestureRecognizer` and `LongPressGestureRecognizer` on the same `Image` element. + +## Project structure + +| File | Purpose | +|------|---------| +| `MainPage.xaml` | UI with three interactive demos | +| `MainPage.xaml.cs` | Event handlers for `LongPressed` and `LongPressing` | +| `ViewModels/LongPressViewModel.cs` | MVVM ViewModel with commands and bindable properties | + +## Prerequisites + +- .NET 11 Preview 3 or later +- .NET MAUI workload (`dotnet workload install maui`) + +## Running the sample + +```bash +dotnet build -t:Run -f net11.0-maccatalyst +``` + +## Platform notes + +| Feature | Android | iOS / Mac Catalyst | +|---------|---------|-------------------| +| `MinimumPressDuration` | System default (~400 ms) | Fully configurable | +| `NumberOfTouchesRequired` | Always 1 | Configurable | +| State tracking | Completed / Canceled only | Full (Started / Running / Completed / Canceled) |