diff --git a/MahApps.Metro/Controls/MetroTouchThumb.cs b/MahApps.Metro/Controls/MetroTouchThumb.cs new file mode 100644 index 0000000000..a01bc4f6a7 --- /dev/null +++ b/MahApps.Metro/Controls/MetroTouchThumb.cs @@ -0,0 +1,53 @@ +using System.Windows.Controls.Primitives; +using System.Windows.Input; + +namespace MahApps.Metro.Controls +{ + public class MetroTouchThumb : Thumb + { + private TouchDevice _currentDevice = null; + + protected override void OnPreviewTouchDown(TouchEventArgs e) + { + // Release any previous capture + ReleaseCurrentDevice(); + // Capture the new touch + CaptureCurrentDevice(e); + } + + protected override void OnPreviewTouchUp(TouchEventArgs e) + { + ReleaseCurrentDevice(); + } + + protected override void OnLostTouchCapture(TouchEventArgs e) + { + // Only re-capture if the reference is not null + // This way we avoid re-capturing after calling ReleaseCurrentDevice() + if (_currentDevice != null) + { + CaptureCurrentDevice(e); + } + } + + private void ReleaseCurrentDevice() + { + if (_currentDevice != null) + { + // Set the reference to null so that we don't re-capture in the OnLostTouchCapture() method + var temp = _currentDevice; + _currentDevice = null; + ReleaseTouchCapture(temp); + } + } + + private void CaptureCurrentDevice(TouchEventArgs e) + { + bool gotTouch = CaptureTouch(e.TouchDevice); + if (gotTouch) + { + _currentDevice = e.TouchDevice; + } + } + } +} diff --git a/MahApps.Metro/MahApps.Metro.NET45.csproj b/MahApps.Metro/MahApps.Metro.NET45.csproj index ed1ff51213..afed78661a 100644 --- a/MahApps.Metro/MahApps.Metro.NET45.csproj +++ b/MahApps.Metro/MahApps.Metro.NET45.csproj @@ -162,6 +162,7 @@ + @@ -721,4 +722,4 @@ --> - \ No newline at end of file + diff --git a/MahApps.Metro/MahApps.Metro.csproj b/MahApps.Metro/MahApps.Metro.csproj index 406d81223e..06e9091101 100644 --- a/MahApps.Metro/MahApps.Metro.csproj +++ b/MahApps.Metro/MahApps.Metro.csproj @@ -127,6 +127,7 @@ + diff --git a/MahApps.Metro/Styles/Controls.Slider.xaml b/MahApps.Metro/Styles/Controls.Slider.xaml index d14f8d0585..e4c808edd9 100644 --- a/MahApps.Metro/Styles/Controls.Slider.xaml +++ b/MahApps.Metro/Styles/Controls.Slider.xaml @@ -1,6 +1,7 @@  + xmlns:System="clr-namespace:System;assembly=mscorlib" + xmlns:controls="clr-namespace:MahApps.Metro.Controls"> 16 10 @@ -185,11 +186,11 @@ Style="{StaticResource HorizontalTrackLargeDecrease}" /> - + @@ -396,11 +397,11 @@ Style="{StaticResource VerticalTrackLargeDecrease}" /> - +