I have this Slider in WPF :
<Slider x:Name="SizeSlider" IsManipulationEnabled="True" Width="100" Minimum="1" Maximum="10" Value="1" ValueChanged="SizeSlider_ValueChanged"></Slider>
I can drag the slider's cursor with the mouse, but not with touch input.
What do I need to do in order to use the slider with touch input ?
So I found the solution, thanks to the link provided by Agentlien.
In XAML, add a TouchDown attribute :
<Slider x:Name="SizeSlider" Width="100" Minimum="1" Maximum="10" Value="1" ValueChanged="SizeSlider_ValueChanged" TouchDown="SizeSlider_TouchDown"/>
(I also removed the IsManipulationEnabled property as it is not necessary here)
In C# code-behind :
private void SizeSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
// Things you want to do everytime slider's value change
// For example :
_brushSize = e.NewValue;
}
private void SizeSlider_TouchDown(object sender, TouchEventArgs e)
{
// Mark event as handled
e.Handled = true;
}
Like this, the slider can be used with both mouse and touch input.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With