From 556cc32755723a92fa4e987e26c2d280c849a86c Mon Sep 17 00:00:00 2001 From: Yang CAO Date: Wed, 25 Mar 2015 16:09:50 +0100 Subject: [PATCH 1/3] create new class of Thumb in order to be better in Touch environment --- MahApps.Metro/Controls/MetroTouchThumb.cs | 53 +++++++++++++++++++++++ MahApps.Metro/MahApps.Metro.csproj | 1 + MahApps.Metro/Styles/Controls.Slider.xaml | 23 +++++----- 3 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 MahApps.Metro/Controls/MetroTouchThumb.cs 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.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}" /> - + From c5a5e9c083d5f9ff718b26f8cd4710139348be55 Mon Sep 17 00:00:00 2001 From: ycaoyang Date: Mon, 29 Jun 2015 18:15:02 +0200 Subject: [PATCH 2/3] Update MahApps.Metro.NET45.csproj --- MahApps.Metro/MahApps.Metro.NET45.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 + From 8644843c6c24dbc2009793aa20066fc15e9dedce Mon Sep 17 00:00:00 2001 From: ycaoyang Date: Mon, 29 Jun 2015 18:20:38 +0200 Subject: [PATCH 3/3] Update MahApps.Metro.NET45.csproj