xaml
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<ScrollViewer x:Name="ScrollViewer1" CanContentScroll="True" SnapsToDevicePixels="True" VerticalScrollBarVisibility="Visible">
<DockPanel LastChildFill="False">
<RadioButton x:Name="RadioButton1" Content="RadioButton1" GroupName="MyGroup" Width="100" DockPanel.Dock="Top" Margin="30"/>
<RadioButton x:Name="RadioButton2" Content="RadioButton2" GroupName="MyGroup" Width="100" DockPanel.Dock="Top" Margin="30"/>
<RadioButton x:Name="RadioButton3" Content="RadioButton3" GroupName="MyGroup" Width="100" DockPanel.Dock="Top" Margin="30"/>
<RadioButton x:Name="RadioButton4" Content="RadioButton4" GroupName="MyGroup" Width="100" DockPanel.Dock="Top" Margin="30"/>
<RadioButton x:Name="RadioButton5" Content="RadioButton5" GroupName="MyGroup" Width="100" DockPanel.Dock="Top" Margin="30"/>
<RadioButton x:Name="RadioButton6" Content="RadioButton6" GroupName="MyGroup" Width="100" DockPanel.Dock="Top" Margin="30"/>
<RadioButton x:Name="RadioButton7" Content="RadioButton7" GroupName="MyGroup" Width="100" DockPanel.Dock="Top" Margin="30"/>
<RadioButton x:Name="RadioButton8" Content="RadioButton8" GroupName="MyGroup" Width="100" DockPanel.Dock="Top" Margin="30"/>
</DockPanel>
</ScrollViewer>
</Window>
vb.net
Class MainWindow
Private Sub RadioButton5_Checked(sender As Object, e As RoutedEventArgs) Handles RadioButton5.Checked
ScrollViewer1.ScrollToVerticalOffset(0)
End Sub
End Class
If you click RadioButton5
you will see that ScrollViewer1
scrolls to the zero position. So, the above codes work great.
I want ScrollViewer1
to scroll to the RadioButton3
position when The User clicks RadioButton8
.
The answer from Robert Levy looks good but I don't understand how to implement Robert Levy's answer here: How to scroll WPF ScrollViewer's content to specific location