# exact width between ticks

1. ##### Wim van der Linden
37 posts
Member since:
Nov 2008

Posted 29 May 2009 Link to this post

Hello,

I was wondering how to retrieve the exact width between ticks.
I was using Width / Maximum because TickFrequency is set to 1.
however this is of course not 100% correct. the width between each tick is a little less then that value.

can somebody point me in the direction how to get the Actualwidth of a tick?
because when i use a ticktemplate and retrieve it the ActualWidth remains 0 (checked in the layoutupdated event so the value should have been set). And setting the ticktemplates width messes the layout up, so thats not an option.

without the custom tick template the width problem is identical so thats not the issue here.

Wim.
2. ##### Dimitrina
442 posts

Posted 01 Jun 2009 Link to this post

Hello Wim,

the way we calculate the distance (in pixels) between the ticks is by using the ratio between the range (maximum - minumum) and the size of the slider.
Therefore, to calculate the position of each tick, we can use a loop where the position of each tick is set in the following manner:

for (double tickValue = this.TickFrequency; tickValue < (this.Maximum - this.Minimum); tickValue += this.TickFrequency)
{
double tickPosition = (tickValue * this.ActualWidth) / (this.Maximum - this.Minimum);
}

For example, assume you have a slider with the following properties:

Width/ActualWidth = 300px,
Minimum = 10,
Maximum = 50,
TickFrequency = 1.

This means that the tick immediately after the minimum will be positioned at (1 * 300) / (50 - 10) == 7.5px, the second at (2 * 300) / (50 - 10) == 15px and so on.

Basically this is it. If something is not clear or you have additional questions, do not hesitate to contact us.

Kind regards,
Dimitrina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
3. ##### Wim van der Linden
37 posts
Member since:
Nov 2008

Posted 02 Jun 2009 Link to this post

Hello Dimitrina,

Your explanation is clear to me, however it gives me the same issue as the caculation I did.
the problem for me is when i'm close to 0 the offset is to the left and close to the maximum value the offset is to the right.

because this is a little hard to understand i'll create a support ticket with a sample project.

Kind regards,
Wim