Prevent LongListMultiSelector from "automatically scrolling" when inserting elements at the beginning

I am using LongListMultiSelector to display messages. The latest messages in botton - as in the messenger. I know that there is a button in the ListHeaderTemplate that allows you to load earlier messages and paste them at the top of the list ( ObservableCollection.Insert(0, item);).

The insert works, but it looks like the list automatically scrolls to the last inserted item - in fact, it does not scroll, but it looks like it scrolls because after the insert, a new element is displayed, but I'm rather looking for a solution that keeps the element visible, which was first before the new elements that were inserted, and that I have to do another vertical scroll to a new vertex in order to get back to the list header.

Any clues?

EDIT 1

count oldFirstItemis the current first element, then I insert a new element in front of the element. now the new element becomes the first element, and since the scroll position does not change, the new element is visible: it seems that the list scrolls to the newly inserted element, but it only pushed elements 1 to n down. I want him to push all the new elements up - in the area that the user does not see - and oldFirstItemat the top of the elements that are displayed. using ScrollTo makes this list jumpy.

EDIT 2 I added an image, trying to show what I want to achieve. The area above the red line is not visible.enter image description here

+4
source share
4 answers

, -, 100%

, ,

<phone:PhoneApplicationPage >

<ScrollViewer x:Name="Scroll" VerticalAlignment="Bottom" Height="500" ScrollViewer.VerticalScrollBarVisibility="Disabled">
    <StackPanel VerticalAlignment="Bottom" >
        <toolkit:LongListMultiSelector x:Name="DataList" ItemsSource="{Binding}" ScrollViewer.VerticalScrollBarVisibility="Disabled" VerticalAlignment="Bottom"
        VirtualizingStackPanel.VirtualizationMode="Recycling"></toolkit:LongListMultiSelector>
    </StackPanel>
</ScrollViewer>

</phone:PhoneApplicationPage>

, , . . ScrollViewer ( )

, ,

    Scroll.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
    Scroll.ScrollToVerticalOffset(DataList.ActualHeight);

, , , , , ScrollToVerticalOffset . - ScrollToVerticalOffset VerticalScrollBarVisibility. , , .

-1

, , - ListHeader , . - , :

var temp = MyLongListMultiSelector.ListHeader; //also works with ListHeaderTemplate
MyLongListMultiSelector.ListHeader = null;
MyObservableCollection.Insert(0, item);    
MyLongListMultiSelector.ListHeader = temp;

add top, :

MyLongListMultiSelector.Remove(fakeHeaderItem);
MyObservableCollection.Insert(0, item); 
MyObservableCollection.Insert(0, fakeHeaderItem); 
-1

you can easily achieve this by adding new elements to the top of the observed collection

obsData.Insert(0,newItem)

Link

-1
source

If I see ... you can use the method ScrollTo.

yourLongListMultiSelector.ScrollTo(yourNewInsertedItem);
-2
source

All Articles