05-09-2014 03:24 AM
Hello,
i've got a Slider that looks like this.
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
Solved! Go to Solution.
05-09-2014 01:14 PM
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.
05-12-2014 01:02 AM
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
05-12-2014 07:27 AM
i made it via Code-behind. Thanks.
Manuel
08-11-2015 01:02 PM
Just wanted to let you know that we have added support for value fill modes in the Measurement Studio 2015 release.