Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

A Clickable Windows Phone Slider

DZone's Guide to

A Clickable Windows Phone Slider

· Mobile Zone
Free Resource

Launching an app doesn’t need to be daunting. Whether you’re just getting started or need a refresher on mobile app testing best practices, this guide is your resource! Brought to you in partnership with Perfecto

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;
            }
        }

Keep up with the latest DevTest Jargon with the latest Mobile DevTest Dictionary. Brought to you in partnership with Perfecto.

Topics:

Published at DZone with permission of Tim Dams, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}