marc wellman
marc wellman

Reputation: 5886

Precision issue with the Silverlight Slider and it's thumb

I have a precision problem with the slider control in Silverlight:

I've built some custeom template to slightly modify the visual appreance of the standard Silverlight slider control. My goal is to have a slider that represents it's values as drawn ticks on it's scale. The corresponding thumb is also slightly modified in the form, that it has a 'tip' (or 'peak') at it's very center to point at the current value at the slider.

--> Here's a snapshot it: http://www.willzeit.at/sliderThumb.jpg

Actually everything works, but I've encountered a very strange behavior of the thumb:

The position on the thumb that points to the current value at the slider seems to change from the left-most position on the thumb to the right-most position on the thumb!

So in the case the thumb is located at it's left-most position with respect to the slider the point on the thumb pointing to the slider-value is the left_most position on the thumb.

Of course the same holds if the thumb is at it's right-most position where the value-indicating position on the thumb is at it's right most position.

Of course that makes sense because the thumb won't be able to go beyond the boundaries of it's slider and therefor the 'value-indication' point on the thumb has to range over the whole width of the thumb (in case of an horizontal slider as in my case).

BUT: That's a significant loss of precision in the 'syncronization' between thumb and slider (of course only when you want to indicate the exact value of the slider with the thumb.

As i said, i need to build a slider that presents values (shown with ticks and labels) and a thumb with a needle. When the user wants to set a particular value with the slider control, he has to move the thumb in the way that it's 'needle' comes to rest beneath this particular value.

I hope i could make this issue clear and also my problem :) Does anybody have any ideas ? I guess there must be a way to solve this problem - otherwise the slider control is not intended to be used in such a way - what sounds highly unlikely for me ...

I really would appreciate any help :) marc

Upvotes: 1

Views: 432

Answers (1)

AnthonyWJones
AnthonyWJones

Reputation: 189505

Theoretically all you need is to make the Silder control think that its thumb is only 1 pixel wide. You can do this by modifying the Thumb template so that the top element in the template is a Canvas (a Grid clips its contents) and then contain the rest of the content in a Grid that you give a specific size to and then offset its left edge. Use an odd number for the width and set its left position = -1 * (Width -1) / 2. You can do this with margin, canvas left or a render transform.

Now I say "Theoretically" because in practice I've come across an anomoly that I just can't explain. No matter how hard I try only the Left hand side of the thumb is active. Silverlight just does not seem to want to recognise the right hand side of the thumb.

Ultimately I decided to put this answer out because clearly you are already editing the templates for control and perhaps if you apply it to your own work you won't get this anomoly.

Upvotes: 1

Related Questions