Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slider.Minimum property negative value issue

Probably I've got another unsolvable problem. In Silverlight XAML, I am unable to set by Style negative value for Slider.Minimum property. I mean, it is possible, but the results are unexpected. In WPF this does work normally.

<StackPanel Width="200" Orientation="Vertical">
    <StackPanel.Resources>
        <Style TargetType="Slider" x:Key="style">
            <Setter Property="Minimum" Value="-10" />
            <Setter Property="Maximum" Value="10" />
            <Setter Property="Value" Value="0" />
        </Style>
    </StackPanel.Resources>
    <!-- Here it is not working -->
    <Slider Style="{StaticResource style}"/>
    <!-- Here it works as expected, as it is not styled -->
    <Slider Minimum="-10" Maximum="10" Value="0" />
</StackPanel>

The result is like this:

enter image description here

But obviously both thumbs should be in the same position (in the middle of Slider).

In fact, it look's like the Minimum value (-10) is accepted, but then Maximum value becomes 0, and that is why the first slider has a thumb aligned to a right side (Value is 0 and Maximum is also 0).

like image 305
infografnet Avatar asked Jul 18 '26 18:07

infografnet


1 Answers

The problem is the HorizontalTemplate of the Slider. If you change the Orientation of the Slider to Vertical then the values defined in your style get applied as expected.

Update: The Solution is to set the Orientation also in the style. Then it works as expected.

<Style TargetType="Slider" x:Key="style">
  <Setter Property="Minimum"
          Value="-10" />
  <Setter Property="Maximum"
          Value="10" />
  <Setter Property="Value"
          Value="0" />
  <Setter Property="Orientation"
          Value="Horizontal" />
 </Style>
like image 63
Jehof Avatar answered Jul 20 '26 19:07

Jehof