Zain Shaikh
Zain Shaikh

Reputation: 6043

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

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?

Upvotes: 0

Views: 1039

Answers (1)

ChrisF
ChrisF

Reputation: 137148

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.

Upvotes: 2

Related Questions