Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slider not working with touch input

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 ?

like image 759
Michaël Polla Avatar asked Jul 07 '13 23:07

Michaël Polla


1 Answers

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.

like image 138
Michaël Polla Avatar answered Oct 07 '22 02:10

Michaël Polla