views:

20

answers:

1

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?

+1  A: 

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.

ChrisF