locked
ScrollIntoView method doesn't on Windows 8.1 RRS feed

  • Question

  • Hi!

    I have a Windows 8 app which I converted it to Windows 8.1 and now the ScrollIntoView method doesn't work anymore. I ran the program step by step to make sure it reaches that part of code, but nothing happens there.

    Here is my code:

    private void itemListView_Loaded(object sender, RoutedEventArgs e)
    {
            SByte day = (SByte)DateTime.Now.Day;
    
            this.itemListView.SelectedItem = this.itemListView.Items[day - 1];
            this.itemListView.ScrollIntoView(itemListView.SelectedItem);
    }

    The data used behind are hundred percent valid, since the Win8 app version runs perfectly.


    Cris

    Thursday, December 12, 2013 10:05 AM

Answers

  • Hi!

    The moment you said I have to wait I realized I could do a dispatcher to wait a few milliseconds and then call a method that does the same thing as the itemListView_Loaded.

    TimeSpan period = TimeSpan.FromMiliseconds(100);
    
    Windows.System.Threading.ThreadPoolTimer.CreateTimer(async (source) => 
                 {
                        await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, Load());
                 }
        , period);

    This solved my problem :)


    Cris


    • Marked as answer by C. Cristi Tuesday, December 17, 2013 3:43 PM
    • Edited by C. Cristi Tuesday, December 17, 2013 3:43 PM Indentation
    Tuesday, December 17, 2013 3:42 PM

All replies

  • Hi Cris,

    Can you try your code by a button click event? I saw you are running the code while the ListView is loaded, I'm not sure if the ListViewItems are completed rendered too. 

    And could you give me a win8 version code and I will try to migrate to 8.1 to reproduce your issue.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, December 12, 2013 1:00 PM
    Moderator
  • Hi!

    I tried to put a button with the load Event of the ListView and it really works. It's very awkward that it doesn't work when I open the app.

    Anyway, here is my code snipped. It goes to current day in list but it depends on the title page, as you can see.

            private void itemListView_Loaded(object sender, RoutedEventArgs e)
            {
                SByte day = (SByte)DateTime.Now.Day;
                SByte month = (SByte)DateTime.Now.Month;
    
                    if (SettingsUserPage.GetResult() != null)
                    {
                        SByte index = (SByte)this.itemListView.Items.IndexOf(SettingsUserPage.GetResult());
                        this.itemListView.SelectedItem = this.itemListView.Items[index];
                        this.itemListView.ScrollIntoView(this.itemListView.Items[index]);
                        SettingsUserPage.SetResult(null);
                    }
                    else
                        if (this.pageTitle.Text == "Ianuarie" && month == 1)
                        {
                            this.itemListView.SelectedItem = this.itemListView.Items[day - 1];
                            this.itemListView.ScrollIntoView(this.itemListView.Items[day - 1]);
                        }
                        else
                            if (this.pageTitle.Text == "Februarie" && month == 2)
                            {
                                this.itemListView.SelectedItem = this.itemListView.Items[day - 1];
                                this.itemListView.ScrollIntoView(this.itemListView.Items[day - 1]);
                            }
                            else
                                if (this.pageTitle.Text == "Martie" && month == 3)
                                {
                                    this.itemListView.SelectedItem = this.itemListView.Items[day - 1];
                                    this.itemListView.ScrollIntoView(this.itemListView.Items[day - 1]);
                                }
                                else
                                    if (this.pageTitle.Text == "Aprilie" && month == 4)
                                    {
                                        this.itemListView.SelectedItem = this.itemListView.Items[day - 1];
                                        this.itemListView.ScrollIntoView(this.itemListView.Items[day - 1]);
                                    }
                                    else
                                        if (this.pageTitle.Text == "Mai" && month == 5)
                                        {
                                            this.itemListView.SelectedItem = this.itemListView.Items[day - 1];
                                            this.itemListView.ScrollIntoView(this.itemListView.Items[day - 1]);
                                        }
                                        else
                                            if (this.pageTitle.Text == "Iunie" && month == 6)
                                            {
                                                this.itemListView.SelectedItem = this.itemListView.Items[day - 1];
                                                this.itemListView.ScrollIntoView(this.itemListView.Items[day - 1]);
                                            }
                                            else
                                                if (this.pageTitle.Text == "Iulie" && month == 7)
                                                {
                                                    this.itemListView.SelectedItem = this.itemListView.Items[day - 1];
                                                    this.itemListView.ScrollIntoView(this.itemListView.Items[day - 1]);
                                                }
                                                else
                                                    if (this.pageTitle.Text == "August" && month == 8)
                                                    {
                                                        this.itemListView.SelectedItem = this.itemListView.Items[day - 1];
                                                        this.itemListView.ScrollIntoView(this.itemListView.Items[day - 1]);
                                                    }
                                                    else
                                                        if (this.pageTitle.Text == "Septembrie" && month == 9)
                                                        {
                                                            this.itemListView.SelectedItem = this.itemListView.Items[day - 1];
                                                            this.itemListView.ScrollIntoView(this.itemListView.Items[day - 1]);
                                                        }
                                                        else
                                                            if (this.pageTitle.Text == "Octombrie" && month == 10)
                                                            {
                                                                this.itemListView.SelectedItem = this.itemListView.Items[day - 1];
                                                                this.itemListView.ScrollIntoView(this.itemListView.Items[day - 1]);
                                                            }
                                                            else
                                                                if (this.pageTitle.Text == "Noiembrie" && month == 11)
                                                                {
                                                                    this.itemListView.SelectedItem = this.itemListView.Items[day - 1];
                                                                    this.itemListView.ScrollIntoView(this.itemListView.Items[day - 1]);
                                                                }
                                                                else
                                                                    if (this.pageTitle.Text == "Decembrie" && month == 12)
                                                                    {
                                                                        this.itemListView.SelectedItem = this.itemListView.Items[day - 1];
                                                                        this.itemListView.ScrollIntoView(this.itemListView.Items[day - 1]);
                                                                    }
                                                                    else
                                                                    {
                                                                        this.itemListView.SelectedItem = this.itemListView.Items[0];
                                                                    }
    }


    Cris

    Friday, December 13, 2013 1:23 PM
  • Hi Cristi,

    The issue might be other controls in your page are not complete loaded while your ListView is loaded. Hardly to say how to solve this problem but you have to wait until all the items are rendered, as I suggested in the first reply, you may need a event that can fire the ListView.ScrollIntoView() after everything is ready.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, December 16, 2013 2:56 AM
    Moderator
  • Hi!

    The moment you said I have to wait I realized I could do a dispatcher to wait a few milliseconds and then call a method that does the same thing as the itemListView_Loaded.

    TimeSpan period = TimeSpan.FromMiliseconds(100);
    
    Windows.System.Threading.ThreadPoolTimer.CreateTimer(async (source) => 
                 {
                        await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, Load());
                 }
        , period);

    This solved my problem :)


    Cris


    • Marked as answer by C. Cristi Tuesday, December 17, 2013 3:43 PM
    • Edited by C. Cristi Tuesday, December 17, 2013 3:43 PM Indentation
    Tuesday, December 17, 2013 3:42 PM
  • Cool, that's the one, thank you for share with us.

    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, December 18, 2013 12:56 AM
    Moderator