Rajeev Bhatia
Rajeev Bhatia

Reputation: 2994

Slider with labels WinRT

I am creating a WinRT/Windows 8 app that needs a slider with both bottom and top tickbars and a number label below each tick as well indicating the value of each tick.

Something like this

So far I have got the slider with the colors and the tickbars working but I cannot get the labels below the tickbars working.

I know that there was some way to do this in WPF by creating a default class and inheriting it and overriding OnRender but I don't think that will work in WinRT since there is no DrawableContext class.

If anyone has done something like this, please help!

PS: The labels just need to have a single value and not a range value as shown in the image and so does the thumb.

Thanks

Upvotes: 4

Views: 2496

Answers (2)

Patrick Finnigan
Patrick Finnigan

Reputation: 1947

Here's how it's done in WPF: http://social.msdn.microsoft.com/Forums/vstudio/en-US/8d64b2dc-4dfd-4b05-aa95-e24aaaed53af/i-want-to-add-lables-with-text-in-ticks-of-slider

Correct, there's no OnRender() in WinRT XAML. As Tim points out, you can retemplate Slider and make your own custom TickBar. It can override ArrangeOverride() and create custom tick marks using Line or Rectangle with labels created using TextBlock. If you don't need a generic solution, you could just overlay the Slider with TextBlocks for the labels.

Upvotes: 1

Tim Heuer
Tim Heuer

Reputation: 4301

In order to get the UI you want, you'll have to re-template the Slider and TickBar within it do get the values to show.

Upvotes: 1

Related Questions