A clickable Windows Phone slider

The default behavior of the Windows Phone Slides control doens’t allow a user to click on the slider where the value should be set to. Instead, tapping anywhere on the slider will simply result in the slider incrementing by it’s default or given incrementsetting.

Following small piece of code shows how to have the wanted behavior by responding to the Tap- event of the Slider (named mySlider in the following codepiece).

        private void UIElement_OnTap(object sender, GestureEventArgs e)
        {
           if (mySlider.Orientation == System.Windows.Controls.Orientation.Horizontal)
            {
                var pos = e.GetPosition(mySlider).X;
                var width = mySlider.ActualWidth;
                mySlider.Value = (pos/width)*mySlider.Maximum;
            }
            else
            {
                var pos = e.GetPosition(mySlider).Y;
                var height = mySlider.ActualHeight;
                mySlider.Value =(1- (pos / height) )* mySlider.Maximum;
            }
        }
About these ads

About timdams
C#, .NET, Microsoft, security, .... Read more on : http://timdams.com/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 327 other followers

%d bloggers like this: