Skip to content
Open
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
22 changes: 22 additions & 0 deletions functions/private/Set-WinUtilSliderFromTouch.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function Set-WinUtilSliderFromTouch {
<#
.SYNOPSIS
Moves a Slider's value to a horizontal touch position. WPF Sliders ignore touch drag on touch-only devices, so this is wired up to the touch events manually.
#>
param (
[Parameter(Mandatory)] $Slider,
[Parameter(Mandatory)] [double]$PositionX
)

if ($Slider.ActualWidth -le 0) { return }

$ratio = [math]::Min(1, [math]::Max(0, $PositionX / $Slider.ActualWidth))
$value = $Slider.Minimum + ($ratio * ($Slider.Maximum - $Slider.Minimum))

if ($Slider.TickFrequency -gt 0) {
$steps = [math]::Round(($value - $Slider.Minimum) / $Slider.TickFrequency)
$value = $Slider.Minimum + ($steps * $Slider.TickFrequency)
}

$Slider.Value = $value
}
22 changes: 22 additions & 0 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,28 @@ $sync["FontScalingSlider"].Add_ValueChanged({
$sync.FontScalingValue.Text = "$percentage%"
})

# WPF sliders don't respond to touch drag, so drive the value from touch events
$sync["FontScalingSlider"].Add_PreviewTouchDown({
param($slider, $e)
$slider.CaptureTouch($e.TouchDevice) | Out-Null
Set-WinUtilSliderFromTouch -Slider $slider -PositionX $e.GetTouchPoint($slider).Position.X
$e.Handled = $true
})

$sync["FontScalingSlider"].Add_PreviewTouchMove({
param($slider, $e)
if ($slider.AreAnyTouchesCaptured) {
Set-WinUtilSliderFromTouch -Slider $slider -PositionX $e.GetTouchPoint($slider).Position.X
$e.Handled = $true
}
})

$sync["FontScalingSlider"].Add_PreviewTouchUp({
param($slider, $e)
$slider.ReleaseTouchCapture($e.TouchDevice) | Out-Null
$e.Handled = $true
})

$sync["FontScalingResetButton"].Add_Click({
$sync.FontScalingSlider.Value = 1.0
$sync.FontScalingValue.Text = "100%"
Expand Down
2 changes: 2 additions & 0 deletions xaml/inputXML.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,8 @@
TickFrequency="0.25"
TickPlacement="BottomRight"
IsSnapToTickEnabled="True"
IsMoveToPointEnabled="True"
Stylus.IsPressAndHoldEnabled="False"
Width="120"
VerticalAlignment="Center"/>
<TextBlock Text="Large"
Expand Down
Loading