Seaky Lone
Seaky Lone

Reputation: 1031

UWP StartBringIntoView not working in Page_Loaded

I have 3 BladeItems in another page. And I want to navigate from MainPage to that page and bring the requested BladeItem into view. But it is not working.

I first thought it was because that the page has not been loaded. So I put it into the Page_Loaded. However, it is still now working. Why is that?

    private void Page_Loaded(object sender, RoutedEventArgs e)
    {
        TitleBarHelper.SetDarkTitleBar();
        Window.Current.SetTitleBar(AppTitleBar);
        UpdateTitleBarLayout(Windows.ApplicationModel.Core.CoreApplication.GetCurrentView().TitleBar);

        FullMediaControl.Update();
        SetMusic(MediaHelper.CurrentMusic);
        FullPlaylistControl.ScrollToMusic(MediaHelper.CurrentMusic);

        if (MusicInfoRequestedWhenUnloaded)
        {
            MusicPropertyBladeItem.StartBringIntoView();
            MusicInfoRequestedWhenUnloaded = false;
        }
        else if (LyricsRequestedWhenUnloaded)
        {
            LyricsBladeItem.StartBringIntoView();
            LyricsRequestedWhenUnloaded = false;
        }
    }

Source Page Code is here. This page can be navigated using the "Show Lyrics" or "Music Info" item in the MenuFlyout at the right bottom more button.

And actually the FullPlaylistControl.ScrollToMusic in the code above is also not working. It just scrolls to a row in a ListView. I guess they might be the same reason.

Upvotes: 0

Views: 156

Answers (1)

Anran Zhang
Anran Zhang

Reputation: 7727

This is the documentation for StartBringIntoView.

According to the instructions in the documentation, this method is only possible when the control is rendered on the visual tree, so you need to modify it when you call the method.

You want MusicPropertyBladeItem.StartBringIntoView() to work, you need to call it in the MusicPropertyBladeItem_Loaded event. For the same reason, you need to call ScrollToMusic when the FullPlaylistControl is loaded.

Page_Loaded only means that the page is loaded, but it doesn't mean that the controls have been rendered.

Best ragards.

Upvotes: 1

Related Questions