Compartilhar via


Como: Rolar Conteúdo Usando a Interface IScrollInfo

This example shows how to scroll content by using the IScrollInfo interface.

Exemplo

The following example demonstrates the features of the IScrollInfo interface. The example creates a StackPanel element in Extensible Application Markup Language (XAML) that is nested in a parent ScrollViewer. Elementos filho do StackPanel pode ser rolado logicamente usando os métodos definidos pelo IScrollInfo interface e reforço à instância do StackPanel (sp1) no código.

<Border BorderBrush="Black" Background="White" BorderThickness="2" Width="500" Height="500">
    <ScrollViewer Name="sv1" CanContentScroll="True" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible">
        <StackPanel Name="sp1">
            <Button>Button 1</Button>
            <Button>Button 2</Button>
            <Button>Button 3</Button>
            <Button>Button 4</Button>
            <Button>Button 5</Button>
            <Rectangle Width="700" Height="500" Fill="Purple"/>
            <TextBlock>Rectangle 1</TextBlock>
            <Rectangle Width="700" Height="500" Fill="Red"/>
            <TextBlock>Rectangle 2</TextBlock>
            <Rectangle Width="700" Height="500" Fill="Green"/>
            <TextBlock>Rectangle 3</TextBlock>
        </StackPanel> 
    </ScrollViewer>
</Border>

Each Button in the XAML file triggers an associated custom method that controls scrolling behavior in StackPanel. The following example shows how to use the LineUp and LineDown methods; it also generically shows how to use all the positioning methods that the IScrollInfo class defines.

Private Sub spLineUp(ByVal sender As Object, ByVal args As RoutedEventArgs)

    CType(sp1, IScrollInfo).LineUp()
End Sub
Private Sub spLineDown(ByVal sender As Object, ByVal args As RoutedEventArgs)

    CType(sp1, IScrollInfo).LineDown()
End Sub
private void spLineUp(object sender, RoutedEventArgs e)
{
    ((IScrollInfo)sp1).LineUp();
}
private void spLineDown(object sender, RoutedEventArgs e)
{
    ((IScrollInfo)sp1).LineDown();
}

Consulte também

Referência

ScrollViewer

IScrollInfo

StackPanel

Conceitos

Visão geral de ScrollViewer

Panels Overview

Outros recursos

Tópicos "Como fazer": ScrollViewer