Como: Use the Content-Scrolling Methods of ScrollViewer
This example shows how to use the scrolling methods of the ScrollViewer element. These methods provide incremental scrolling of content, either by line or by page, in a ScrollViewer.
Exemplo
The following example creates a ScrollViewer named sv1, which hosts a child TextBlock element. Porque o TextBlock é maior do que o pai ScrollViewer, barras de rolagem aparecem habilitar a rolagem. Buttonelementos que representam os diversos métodos de rolagem são encaixados à esquerda em um separado StackPanel. Cada Button na XAML arquivo chama um método personalizado relacionado, que controla o comportamento da rolagem em ScrollViewer.
<StackPanel DockPanel.Dock="Left" Width="150">
<Button Margin="3,0,0,2" Background="White" Click="svLineUp">Adjust Line Up</Button>
<Button Margin="3,0,0,2" Background="White" Click="svLineDown">Adjust Line Down</Button>
<Button Margin="3,0,0,2" Background="White" Click="svLineRight">Adjust Line Right</Button>
<Button Margin="3,0,0,2" Background="White" Click="svLineLeft">Adjust Line Left</Button>
<Button Margin="3,0,0,2" Background="White" Click="svPageUp">Adjust Page Up</Button>
<Button Margin="3,0,0,2" Background="White" Click="svPageDown">Adjust Page Down</Button>
<Button Margin="3,0,0,2" Background="White" Click="svPageRight">Adjust Page Right</Button>
<Button Margin="3,0,0,2" Background="White" Click="svPageLeft">Adjust Page Left</Button>
<TextBlock Name="txt2" TextWrapping="Wrap"/>
</StackPanel>
<Border BorderBrush="Black" Background="White" BorderThickness="2" Height="520" Width="520" VerticalAlignment="Top">
<ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto" Name="sv1">
<TextBlock TextWrapping="Wrap" Width="800" Height="1000" Name="txt1"/>
</ScrollViewer>
</Border>
The following example uses the LineUp and LineDown methods.
Private Sub svLineUp(ByVal sender As Object, ByVal args As RoutedEventArgs)
sv1.LineUp()
End Sub
Private Sub svLineDown(ByVal sender As Object, ByVal args As RoutedEventArgs)
sv1.LineDown()
End Sub
private void svLineUp(object sender, RoutedEventArgs e)
{
sv1.LineUp();
}
private void svLineDown(object sender, RoutedEventArgs e)
{
sv1.LineDown();
}