Since the positions are scaled or otherwise changed between ScrollViewers, you cannot use simple snapping, but does the converter work?
<Window x:Class="Application1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:SurfaceApplication21" Title="SurfaceApplication21" > <Window.Resources> <local:InvertDoubleConverter x:Key="idc" /> </Window.Resources> <Grid> <StackPanel> <Slider Minimum="-100" Maximum="100" Name="a" Height="23" HorizontalAlignment="Left" Margin="30,12,0,0" VerticalAlignment="Top" Width="100" /> <Slider Minimum="-100" Maximum="100" Value="{Binding ElementName=a, Path=Value, Converter={StaticResource idc}}" Name="b" Height="23" HorizontalAlignment="Left" Margin="30,12,0,0" VerticalAlignment="Top" Width="100" /> </StackPanel> </Grid> </Window>
where you can implement any math needed to scale between two views.
[ValueConversion(typeof(double), typeof(double))] public class InvertDoubleConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo ci) { return -(double)value; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo ci) { return -(double)value; } }
I have not tried using ScrollViewers, but since the scrollbars that are part of the ScrollViewer template and sliders go down from RangeBase, something like this should work, but you may have to re-create the template and / or subclass ScrollViewers.
John muller
source share