Reputation: 2594
Is there a simple way to override the appearance of the Thumb
on a Slider
element without defining a whole custom Slider
style? I want to use the default Slider
, but just change the shape of the thumb to a circle. The questions I've seen so far tend to recommend defining a whole custom Slider
element, but what I'm looking for is a way to override just the thumb without touching the other parts of the style - it seems like there should be some way to do this in a very small number of lines in the xaml file.
Upvotes: 0
Views: 422
Reputation: 7690
Yes. There is. With a little hack. After the style is applied (in OnApplyTemplate() for example), you can do a FindName, ie:
Thumb thumb = Template.FindName("Thumb", this) as Thumb;
then replace the control template:
thumb.Template = ...;
You can't just put a style in your resource section that targets Thumbs because the default style gets overridden in the Slider style, but this is a nice work-around so you don't need to redefine the whole style. You can also put some logic in your thumb.Template line to pick a different template if you're vertical or horizontal or on the OS, etc.
Upvotes: 1