9

我希望收到有关 ScrollViewer 垂直滚动条的 VerticalOffset 更改的通知。在 WPF 中有一个 ScrollViewer.ScrollChanged 事件,但在 Silverlight 3 中缺少此事件。有谁知道解决方法?

4

3 回答 3

6

您可以使用元素绑定,这是一个愚蠢的示例:-

<Grid x:Name="LayoutRoot" Background="White">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="100" />
        <ColumnDefinition Width="100" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="60" />
    </Grid.RowDefinitions>
    <ScrollViewer x:Name="ScrollSource">
        <StackPanel>
            <TextBlock>Hello</TextBlock>
            <TextBlock>World</TextBlock>
            <TextBlock>Yasso</TextBlock>
            <TextBlock>Kosmos</TextBlock>
        </StackPanel>
    </ScrollViewer>
    <TextBox Grid.Column="1" Text="{Binding VerticalOffset, ElementName=ScrollSource}" />

</Grid>

随着ScrollViewer滚动,TextBox 的 Text 属性被告知新值。

于 2009-11-19T11:11:25.017 回答
3

silverlight 论坛上有一个更简单的解决方案:

protected override Size ArrangeOverride(Size finalSize)
{    
    // Assumes you only have one scrollviewer (e.g. fullscreen ScrollViewer)
    var scrollbar = LayoutRoot.GetVisualDescendants()
        .OfType<ScrollBar>()
        .FirstOrDefault();

    if (scrollbar != null)
        scrollbar.Scroll += ScrollBarScroll;

    return base.ArrangeOverride(finalSize);
}

private void ScrollBarScroll(object sender, ScrollEventArgs e)
{

}
于 2010-05-25T09:34:33.297 回答
1

here is a good link which i found while googling, it also has some sample code which i haven't checked out.

http://dotplusnet.blogspot.com/2010/05/scrollviewer-scroll-change-event-in.html

于 2010-09-14T18:02:14.640 回答