Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

slider range negativ. Fill-value should start at 0

Solved!
Go to solution

Hello,

i've got a Slider that looks like this.

SliderRange.png

the Range is from -50 to 50.

 

Butt the fill-Value starts at -50 to 0. What i've to do that the fill Value always starts at 0.

With Fill-Value i mean the Blue Line.

Thanks

0 Kudos
Message 1 of 5
(5,473 Views)
Solution
Accepted by topic author manuelhoedl

The WPF numeric controls do not have a direct equivalent to the FillMode property in Windows Forms. As a workaround, you can add a custom object to the track and adjust the fill when the value changes:


    XAML
    <ni:SliderDouble x:Name="Slider" Fill="{x:Null}" ValueChanged="OnSliderValueChanged">
        <ni:SliderDouble.TrackDecorations>
            <Rectangle Fill="DarkCyan"
                       niPrimitives:RegionPanel.RelativeWidth="1.0"
                       niPrimitives:RegionPanel.RelativeHeight="0.14"
                       niPrimitives:RegionPanel.RelativeVerticalPosition="0.5"
                       niPrimitives:RegionPanel.RelativeVerticalAlignment="Center">
                <Rectangle.OpacityMask>
                    <LinearGradientBrush x:Name="FillOpacityBrush" StartPoint="1,0" EndPoint="0,0">
                        <GradientStop Color="Transparent" />
                        <GradientStop Color="White" />
                        <GradientStop Color="White" />
                        <GradientStop Color="Transparent" />
                    </LinearGradientBrush>
                </Rectangle.OpacityMask>
            </Rectangle>
        </ni:SliderDouble.TrackDecorations>
    </ni:SliderDouble>

    Code
    private void OnSliderValueChanged( object sender, ValueChangedEventArgs<double> e ) {
        // Get start and end values for fill.
        var mapper = (IDataMapper<double>)Slider.Scale.GetDataMapper( Slider );
        double zeroOffset = mapper.Map( 0.0 );
        double valueOffset = mapper.Map( e.NewValue );

        // Update gradient stops to fill from zero to the new value.
        double beginOffset = Math.Min( zeroOffset, valueOffset );
        double endOffset = Math.Max( zeroOffset, valueOffset );
        var stops = FillOpacityBrush.GradientStops;
        stops[0].Offset = stops[1].Offset = beginOffset;
        stops[2].Offset = stops[3].Offset = endOffset;
    }



Note that this relies on implementation details of the current release of the WPF controls. We intentionally left many of the underlying primitive types with minimal documentation, as we may change them in the future. In the current implementation, we use RegionPanel to perform the layout for many of our controls. Although these exact members may be removed in a later release, we do plan to provide equivalent functionality and stabilize the primitive API over time.


Besides that caveat, I hope you find this useful.

~ Paul H
0 Kudos
Message 2 of 5
(5,462 Views)

Hi Paul,

my Slider is in an Resourcedictionary. I only can access it with attached propertys.

How can i do this the MVVM - Way ?

Thanks

0 Kudos
Message 3 of 5
(5,448 Views)

i made it via Code-behind. Thanks.

Manuel

0 Kudos
Message 4 of 5
(5,440 Views)

Just wanted to let you know that we have added support for value fill modes in the Measurement Studio 2015 release.

~ Paul H
0 Kudos
Message 5 of 5
(4,216 Views)