Question

I'm trying to use in my application an input-selected index to scroll a ListBox (horizontally scrollable). I've found on MSDN and on this own site the method ScrollIntoView but it doesn't work and on the ListBox Class page it has been written to be compatible with WP 7.0, 7.1. So, this is a snapshot of my code...

scrolling.ScrollIntoView(scrolling.Items[20]);

where scrolling is my ListBox and the 20th item is the one I want to be selected and visualized. PS: I've already tried to use the selectedIndex way but it is still not working!

This is a xaml of my ListBox (put in the Layout Grid) which have referencies to templates written in the App.xaml document.

<ListBox x:Name="scrolling"  Grid.Column="0"   ScrollViewer.ManipulationMode ="Control" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Visible">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
    </ListBox>

edit: I found that calling the function by a button makes the all whole stuff work, but how to initialize everything at the start?

Was it helpful?

Solution

I used in my solution first updated UI and then called ScrollIntoView it works fine:

scrolling.UpdateLayout();
scrolling.ScrollIntoView(scrolling.Items[20]);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top