All Projects → davidezordan → multi-touch

davidezordan / multi-touch

Licence: MIT license
Multi-Touch XAML Behaviors implementing Multi-Touch Manipulation (Gestures) and Inertia.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to multi-touch

MahApps.Metro.netcoreapp30
.NET Core 3.1 MahApps.Metro sample
Stars: ✭ 15 (-34.78%)
Mutual labels:  xaml
DialogHost.Avalonia
AvaloniaUI control that provides a simple way to display a dialog with information or prompt the user when information is needed
Stars: ✭ 92 (+300%)
Mutual labels:  xaml
Displaying-XAML
This library is for display the XAML code of theme library for WPF (e.g. MaterialDesignInXamlToolkit)
Stars: ✭ 38 (+65.22%)
Mutual labels:  xaml
Toast
🍞 The rounded and animated Android Toast for .NET WPF/XAML
Stars: ✭ 25 (+8.7%)
Mutual labels:  xaml
IconPacks.Browser
The Browser for all available Icon packages from MahApps.Metro.IconPacks
Stars: ✭ 74 (+221.74%)
Mutual labels:  xaml
AdminRunasMenu
A WPF menu driven by powershell to perform administrator functions
Stars: ✭ 26 (+13.04%)
Mutual labels:  xaml
Quarrel
A UWP discord client
Stars: ✭ 238 (+934.78%)
Mutual labels:  xaml
stm32 i2c to usb hid multitouch
i2c to usb hid multi touch with stm32
Stars: ✭ 55 (+139.13%)
Mutual labels:  multi-touch
ofxTouchPad
Multitouch support for touchpads.
Stars: ✭ 23 (+0%)
Mutual labels:  multi-touch
SharpDiskSweeper
Reveal outstanding files or folders that are eating up your disk space
Stars: ✭ 21 (-8.7%)
Mutual labels:  xaml
LRReader
A feature-complete reader and client for LANraragi
Stars: ✭ 62 (+169.57%)
Mutual labels:  xaml
SpicyTaco.AutoGrid
A magical replacement for the built in WPF Grid and StackPanel
Stars: ✭ 67 (+191.3%)
Mutual labels:  xaml
ReactiveValidation
A small validation library for WPF and Avalonia which uses a fluent interface and allows display messages near controls in GUI with MVVM
Stars: ✭ 50 (+117.39%)
Mutual labels:  xaml
Quick-Pad
Quick Pad is a modern notepad app featuring fluent design
Stars: ✭ 183 (+695.65%)
Mutual labels:  xaml
XamlIslands
Repository with several XAML Islands v1 samples (Win32, WPF, and WinForms) to demonstrate how to use it.
Stars: ✭ 47 (+104.35%)
Mutual labels:  xaml
Wpftoolkit
All the controls missing in WPF. Over 1 million downloads.
Stars: ✭ 2,970 (+12813.04%)
Mutual labels:  xaml
xamarin-forms-statusbar
Xamarin.Forms Effect to manage the StatusBar BackgroundColor.
Stars: ✭ 16 (-30.43%)
Mutual labels:  xaml
SimpleDialogs
💬 A simple framework to help displaying dialogs on a WPF app
Stars: ✭ 24 (+4.35%)
Mutual labels:  xaml
Packet Sender Mobile
iOS and Android version of Packet Sender
Stars: ✭ 58 (+152.17%)
Mutual labels:  xaml
use-pan-and-zoom
👆+🔎 React hook for panning and zooming a container
Stars: ✭ 57 (+147.83%)
Mutual labels:  gestures

Multi-Touch Behaviors

XAML Behaviors implementing Multi-Touch Manipulation (Gestures) and Inertia.

Xamarin Forms Behavior uses code from original Xamarin.Forms samples: https://github.com/xamarin/xamarin-forms-samples/tree/master/WorkingWithGestures

Archived projects targeting Silverlight, WPF and Windows Phone 7.x, 8.x available on CodePlex: http://multitouch.codeplex.com/.

Xamarin.Forms: using the PanGestureRecognizer

Using the PanGestureRecognizer

Recently I've blogged about Xamarin.Forms and how to create a XAML Behavior for enabling Multi-Touch gestures to generic elements and implementing a scale / pinch functionality.

Fortunately the framework provides three types of recognizer that greatly simplify the implementation:

  • PinchGestureRecognizer allows user interactions for zoom / scale functionalities;
  • PanGestureRecognizer enables pan / translate transformations;
  • TapGestureRecognizer detects tap events.

Yesterday I decided to try the PanGestureRecognizer for extending the capabilities of the Behavior described in the previous post.

First of all, I added two Bindable properties in order to permit activation / deactivation of individual gestures (Bindable properties are equivalent to Dependency ones in UWP XAML)

#region IsScaleEnabled property

/// <summary>
/// Identifies the <see cref="IsScaleEnabledProperty" /> property.
/// </summary>
public static readonly BindableProperty IsScaleEnabledProperty =
    BindableProperty.Create<MultiTouchBehavior, bool>(w => w.IsScaleEnabled, default(bool));

/// <summary>
/// Identifies the <see cref="IsScaleEnabled" /> dependency / bindable property.
/// </summary>
public bool IsScaleEnabled
{
    get { return (bool)GetValue(IsScaleEnabledProperty); }
    set { SetValue(IsScaleEnabledProperty, value); }
}

#endregion

#region IsTranslateEnabled property

/// <summary>
/// Identifies the <see cref="IsTranslateEnabledProperty" /> property.
/// </summary>
public static readonly BindableProperty IsTranslateEnabledProperty =
    BindableProperty.Create<MultiTouchBehavior, bool>(w => w.IsTranslateEnabled, default(bool));

/// <summary>
/// Identifies the <see cref="IsTranslateEnabled" /> dependency / bindable property.
/// </summary>
public bool IsTranslateEnabled
{
    get { return (bool)GetValue(IsTranslateEnabledProperty); }
    set { SetValue(IsTranslateEnabledProperty, value); }
}

#endregion

In this way we can specify in our XAML what gestures are enabled:

...
<Image.Behaviors>
     <behaviors:MultiTouchBehavior IsScaleEnabled="True" IsTranslateEnabled="True" />
</Image.Behaviors>
...

Then I initialised the GestureRecognizers adding a new PanGestureRecognizer to the recognizers list:

/// <summary>
/// Initialise the Gesture Recognizers.
/// </summary>
private void InitialiseRecognizers()
{
    _panGestureRecognizer = new PanGestureRecognizer();
}

/// <summary>
/// Occurs when BindingContext is changed: used to initialise the Gesture Recognizers.
/// </summary>
/// <param name="sender">The sender object.</param>
/// <param name="e">The event parameters.</param>
private void AssociatedObjectBindingContextChanged(object sender, EventArgs e)
{
    _parent = _associatedObject.Parent as ContentView;
    _parent?.GestureRecognizers.Remove(_panGestureRecognizer);
    _parent?.GestureRecognizers.Add(_panGestureRecognizer);
}

And subscribed to the PanUpdated event in order to apply the translate transform:

/// <summary>
/// Initialise the events.
/// </summary>
private void InitializeEvents()
{
    CleanupEvents();

    _panGestureRecognizer.PanUpdated += OnPanUpdated;
}

The implementation of this event handler permits to update the X and Y coordinates of the element when a Pan gesture is detected:

/// <summary>
/// Implements Pan/Translate.
/// </summary>
/// <param name="sender">The sender object.</param>
/// <param name="e">The event parameters.</param>
private void OnPanUpdated(object sender, PanUpdatedEventArgs e)
{
    if (_parent == null)
    {
        return;
    }

    if (!IsTranslateEnabled)
    {
        return;
    }

    switch (e.StatusType)
    {
        case GestureStatus.Running:
            _parent.Content.TranslationX = _xOffset + e.TotalX;
            _parent.Content.TranslationY = _yOffset + e.TotalY;
            break;

        case GestureStatus.Completed:
            _xOffset = _parent.Content.TranslationX;
            _yOffset = _parent.Content.TranslationY;
            break;
    }
}

Here we go: the sample app can now be deployed to the emulators and iOS / Android / Windows devices.

Just a couple of notes:

  • deployment to iOS required this workaround to work properly since the new sample app uses different assemblies;
  • Project has been updated to Visual Studio 2019 and Xamarin.Forms 3.6.0.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].