如何在 silverlight 中将 ScrollViewer 的滚动条固定到顶部?

发布于 2024-09-29 14:02:29 字数 759 浏览 2 评论 0原文

我的 xaml 中有一个 ScrollViewer 内的 Itemscontrol。

 
        
            
                <数据模板>
                     
                
            
        
    

这是我分配给 ItemsControl 的列表,

this.itemsStackPanel.ItemsSource = usersList;

现在,只要在 usersList 中添加新项目,UI 就会更新,ScrollViewer 的滚动条会到达底部。我怎样才能把它粘到上面?

--编辑--
我发现的另一个问题是,当滚动查看器水平调整大小时,滚动条会到达底部。如何在调整大小时将滚动条保持在顶部?

I have an Itemscontrol in my xaml inside a ScrollViewer.

   <ScrollViewer Margin="0,0,0,0" BorderThickness="0">
        <ItemsControl x:Name="itemsStackPanel">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <controls:UserItem Margin="0, 5, 0, 3"></controls:UserItem>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </ScrollViewer>

and here is the list I am assigning to ItemsControl,

this.itemsStackPanel.ItemsSource = usersList;

now whenever new items are added in usersList, the UI updates and the scrollbar of ScrollViewer reaches at bottom. how do I stick it to top??

--EDIT--
one more issue I found, is that when ever the scrollviewer is resized horizontally, the scrollbars reach at bottom. how to keep the scrollbars on top while resizing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独孤求败 2024-10-06 14:02:29

一种方法是调用

scrollView.ScrollToVerticalOffset(0);

MSDN 页面

但是,这可能只会导致列表滚动到底部,然后再次滚动到顶部 - 这不是您想要的。

One way would be to call

scrollView.ScrollToVerticalOffset(0);

MSDN page

However, this might just cause the list to scroll to the bottom and then the top again - not what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文