AidanH
AidanH

Reputation: 522

WPF hide slider track

I'm using WPF (and the MVVM framework) to create an interface which has a slider on it.

<Slider Value="{Binding MotorDemandSpeed}" Maximum="3500" />

I'm trying to hide the track part on the slider so that you are left with just the 'thumb tack'. This is what the slider currently looks like (styles are controlled by a theme):

enter image description here

I've looked around at various methods, however I can't find a method that changes only a single slider.

Help is appreciated.

Upvotes: 3

Views: 1796

Answers (2)

Jack
Jack

Reputation: 1006

In order to change the appearance of a control you will need to modify the control template. Each control is made up of many parts, and each part many objects. You can modify individual parts (such as the track) with the correct x:Key and TargetType.

This Question has an example of modifying a scrollbar control template, which is most likely similar to the template of this slider you have. The first step would be to identify the Xaml file in your theme which this slider uses and find the parts that define the trackbar, thumb, etc. From there you should be able to recreate the control to your liking, or just completely remove parts you do not need.

Are you using any third party controls that may have information on how to edit their themes? Perhaps try investigating Modifying Control Templates to get a better understanding of control templates.

Here is the MDSN page for the slider control template, you may find this useful.

Upvotes: 3

mm8
mm8

Reputation: 169320

You need to set the Template property of this particular Slider instance to be able to override its ControlTemplate:

<Slider Value="{Binding MotorDemandSpeed}" Maximum="3500">
    <Slider.Template>
        <ControlTemplate TargetType="Slider">
            <!-- define the custom template without a track here... -->
        </ControlTemplate>
    </Slider.Template>
</Slider>

Upvotes: 4

Related Questions