This is a migrated thread and some comments may be shown as answers.

exact width between ticks

3 Answers 44 Views
Slider
This is a migrated thread and some comments may be shown as answers.
Wim van der Linden
Top achievements
Rank 1
Wim van der Linden asked on 29 May 2009, 09:01 AM
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.

thank you for your time,

Wim.

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 01 Jun 2009, 02:37 PM
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.
0
Wim van der Linden
Top achievements
Rank 1
answered on 02 Jun 2009, 06:55 AM
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
0
Accepted
Kiril Stanoev
Telerik team
answered on 02 Jun 2009, 08:47 AM
Hello Wim,
Please take a look at the support ticket you sent.

Sincerely yours,
Kiril Stanoev
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.
Tags
Slider
Asked by
Wim van der Linden
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Wim van der Linden
Top achievements
Rank 1
Kiril Stanoev
Telerik team
Share this question
or