Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create new class of Thumb in order to be better in Touch environment #1853

Merged
merged 3 commits into from
Oct 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions MahApps.Metro/Controls/MetroTouchThumb.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
3 changes: 2 additions & 1 deletion MahApps.Metro/MahApps.Metro.NET45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
<Compile Include="Controls\MetroProgressBar.cs" />
<Compile Include="Controls\MetroTabControl.cs" />
<Compile Include="Controls\MetroTabItem.cs" />
<Compile Include="Controls\MetroTouchThumb.cs" />
<Compile Include="Controls\MetroWindowHelpers.cs" />
<Compile Include="Controls\MultiFrameImage.cs" />
<Compile Include="Controls\NumericUpDown.cs" />
Expand Down Expand Up @@ -721,4 +722,4 @@
</Target>
-->
<Target Name="AfterCompile" />
</Project>
</Project>
1 change: 1 addition & 0 deletions MahApps.Metro/MahApps.Metro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<Compile Include="Controls\MetroProgressBar.cs" />
<Compile Include="Controls\MetroTabControl.cs" />
<Compile Include="Controls\MetroTabItem.cs" />
<Compile Include="Controls\MetroTouchThumb.cs" />
<Compile Include="Controls\MetroWindowHelpers.cs" />
<Compile Include="Controls\MultiFrameImage.cs" />
<Compile Include="Controls\NumericUpDown.cs" />
Expand Down
23 changes: 12 additions & 11 deletions MahApps.Metro/Styles/Controls.Slider.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib">
xmlns:System="clr-namespace:System;assembly=mscorlib"
xmlns:controls="clr-namespace:MahApps.Metro.Controls">

<System:Double x:Key="HorizontalThumbHeight">16</System:Double>
<System:Double x:Key="HorizontalThumbWidth">10</System:Double>
Expand Down Expand Up @@ -185,11 +186,11 @@
Style="{StaticResource HorizontalTrackLargeDecrease}" />
</Track.IncreaseRepeatButton>
<Track.Thumb>
<Thumb x:Name="HorizontalThumb"
Height="{DynamicResource HorizontalThumbHeight}"
IsTabStop="True"
Width="{DynamicResource HorizontalThumbWidth}"
Style="{StaticResource HorizontalSliderThumb}" />
<controls:MetroTouchThumb x:Name="HorizontalThumb"
Height="{DynamicResource HorizontalThumbHeight}"
IsTabStop="True"
Width="{DynamicResource HorizontalThumbWidth}"
Style="{StaticResource HorizontalSliderThumb}" />
</Track.Thumb>
</Track>
</Grid>
Expand Down Expand Up @@ -396,11 +397,11 @@
Style="{StaticResource VerticalTrackLargeDecrease}" />
</Track.IncreaseRepeatButton>
<Track.Thumb>
<Thumb x:Name="VerticalThumb"
Width="{DynamicResource VerticalThumbWidth}"
IsTabStop="True"
Height="{DynamicResource VerticalThumbHeight}"
Style="{StaticResource VerticalSliderThumb}" />
<controls:MetroTouchThumb x:Name="VerticalThumb"
Width="{DynamicResource VerticalThumbWidth}"
IsTabStop="True"
Height="{DynamicResource VerticalThumbHeight}"
Style="{StaticResource VerticalSliderThumb}" />
</Track.Thumb>
</Track>
</Grid>
Expand Down