开发者

how do I stick the scrollbars of ScrollViewer to top in silverlight?

开发者 https://www.devze.com 2023-01-23 00:29 出处:网络
I have an Itemscontrol in my xaml inside a ScrollViewer. <ScrollViewer Margin=\"0,0,0,0\" BorderThickness=\"0开发者_开发知识库\">

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号