简体   繁体   中英

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):

在此输入图像描述

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

Help is appreciated.

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM