Qortex
Qortex

Reputation: 7456

Styling a slider makes it ineffective

When I put my styling out of a Slider control, it gets all messed up (I can't move the slider anymore, and it's stuck).

Original code (it works):

<Slider IsThumbToolTipEnabled="True" SmallChange="10" Orientation="Horizontal" StepFrequency="10" Minimum="900" Maximum="2500" Value="1300" />

I get that, and it works as expected:

I click to get the tooltip here

Now if I use an external style:

<Style x:Key="ELOSlider" TargetType="Slider">
      <Setter Property="IsThumbToolTipEnabled" Value="True"/>
      <Setter Property="SmallChange" Value="10"/>
      <Setter Property="Orientation" Value="Horizontal"/>
      <Setter Property="StepFrequency" Value="10"/>
      <Setter Property="Minimum" Value="900"/>
      <Setter Property="Maximum" Value="2500"/>
      <Setter Property="Value" Value="1300"/>
</Style>

...

<Slider Style="{StaticResource ELOSlider}" />

It's messed up (the slider is stuck, cannot do anything):

I can't even move the slider

It recognizes the style because otherwise it wouldn't be at 900, but why doesn't the slider appear correctly?

What am I doing wrong? It's really puzzling me.

Upvotes: 0

Views: 198

Answers (1)

Qortex
Qortex

Reputation: 7456

I actually found the issue. It looks like the styling engine applies the Setters sequentially.

It must fail when it tries to set Minimum to 900 because Maximum is at 1 by default. If I put the Setters the other way around as follows, it works nicely. Kind of counterintuitive... Especially as no warning is output (and I would expect 900 to be entirely rejected, not to screw up the control...)

<Style x:Key="ELOSlider" TargetType="Slider">
    <Setter Property="Maximum" Value="2500"/>
    <Setter Property="Value" Value="1300"/>
    <Setter Property="Minimum" Value="900"/>
    <Setter Property="IsThumbToolTipEnabled" Value="True"/>
    <Setter Property="SmallChange" Value="10"/>
    <Setter Property="Orientation" Value="Horizontal"/>
    <Setter Property="StepFrequency" Value="10"/>
</Style>

Upvotes: 1

Related Questions