tags:

views:

425

answers:

1

Hi,

I want to display a Slider ranging from 0.5 to 1.5 with only one tick mark at 1.0 to mark the center and default value. I have defined a Slider as follows:

<Slider Minimum="0.5" Maximum="1.5"
        IsMoveToPointEnabled="True" IsSnapToTickEnabled="False"
        Orientation="Horizontal"
        Ticks="1.0"
        TickPlacement="BottomRight"
        Value="{Binding SomeProperty, Mode=TwoWay}"/>

However, besides a tick mark at 1.0 this Slider also shows tick marks at 0.5 and 1.5, i.e. the Minimum and Maximum values.

Is there a way to hide these min/max tick marks?! I checked all properties and tried changing some of them, but did not have success so far.

Thanks,
gehho.

+1  A: 

One way to do it would be to provide your own ControlTemplate for the Slider. If you take a look at the default Slider ControlTemplate(available on MSDN), you will see the Ticks on the Slider are implemented by a class called TickBar.
Inherit from the TickBar class and override its OnRender() method will allow you to draw the ticks however you want. You can get really creative here: i.e. numbered ticks, different colors/styles etc... Or in your case, simply don't draw ticks at the min/max position.
Then substitute the default TickBar in the custom Slider ControlTemplate with your new TickBar sans min/max ticks, and you are good to go.

For code examples on inheriting from the TickBar look at this: http://social.msdn.microsoft.com/forums/en-US/wpf/thread/6b926273-b0a1-43ab-be81-f2e9b42d701a

The website talks about displaying numbered ticks but you should be able to learn what you need to know from it.

Bojin Li
Thanks for your answer. I did not try this, but I suppose it would work. However, I was looking for an easier solution to it, like setting a property. I think it is bad design if you offer a `Ticks` property and then display tick marks at other positions anyway. Even worse that you cannot make them go away (easily). Anyway, I think I will have to stick with it because I do not want to/cannot take the way you described. I have accepted your answer anyway because it would solve the problem.
gehho