我在另一页中有3个BladeItem
。我想从MainPage
导航到该页面,并将请求的BladeItem
放入视图。但它不起作用。
我首先以为是因为该页面尚未加载。所以我把它放到Page_Loaded中。但是,它现在仍在工作。为什么会这样?
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;
}
}
源页面代码为here。可以使用右下角MenuFlyout
中更多按钮的“显示歌词”或“音乐信息”项目浏览此页面。
并且实际上以上代码中的FullPlaylistControl.ScrollToMusic
也无法正常工作。它只是滚动到ListView
中的一行。我想它们可能是相同的原因。
这是StartBringIntoView的文档。
根据文档中的说明,仅当控件在可视化树上呈现时,才可以使用此方法,因此在调用该方法时需要对其进行修改。
您希望MusicPropertyBladeItem.StartBringIntoView()
工作,您需要在MusicPropertyBladeItem_Loaded
事件中调用它。出于同样的原因,您需要在加载ScrollToMusic
时调用FullPlaylistControl
。
[Page_Loaded
仅表示页面已加载,但并不表示控件已呈现。
最佳服装。