private void GetOwnerAndGenerator() { itemsOwner = ItemsControl.GetItemsOwner(this); if (itemsOwner == null) { throw new InvalidOperationException("无法从 VirtualizingPanel 找到父 ItemsControl."); } if (!(itemsOwner is ListViewBase)) { throw new InvalidOperationException("VirtualizingPanel 应该在 ListView.ItemsPanel 中被调用"); } scrollOwner = VisualTreeExtension.GetParentObject <ScrollViewer>(itemsOwner, "PageScrollViewer"); if (scrollOwner == null) { throw new InvalidOperationException("无法从父 ItemsControl 找到 ScrollView"); } itemContainerGenerator = itemsOwner.ItemContainerGenerator; if (itemContainerGenerator == null) { throw new InvalidOperationException("无法获取 VirtualizingPanel 所属 ItemsControl 的 ItemContainerGenerator"); } if (!isGeneratorHooked) { isGeneratorHooked = true; scrollOwner.ViewChanging -= ScrollOwnerViewChanging; scrollOwner.ViewChanging += ScrollOwnerViewChanging; itemContainerGenerator.ItemsChanged -= ItemContainerGeneratorItemsChanged; itemContainerGenerator.ItemsChanged += ItemContainerGeneratorItemsChanged; } }
private void MenuListView_ItemClick(object sender, ItemClickEventArgs e) { var item = e.ClickedItem as FrameworkElement; var parent = VisualTreeExtension.GetParentObject <ListViewItem>(item, ""); string tag = parent.Tag.ToString(); switch (tag) { case "Message": App.AppViewModel.NavigateToSubPage(typeof(Pages_Share.Sub.Account.MessagePage)); break; case "VideoDynamic": App.AppViewModel.NavigateToSubPage(typeof(Pages_Share.Sub.Video.DynamicPage)); break; case "MyAnime": App.AppViewModel.NavigateToSubPage(typeof(Pages_Share.Sub.Account.FavoriteAnimePage), "anime"); break; case "MyMovie": App.AppViewModel.NavigateToSubPage(typeof(Pages_Share.Sub.Account.FavoriteAnimePage), "cinema"); break; case "MyFavorite": App.AppViewModel.NavigateToSubPage(typeof(Pages_Share.Sub.Account.FavoriteContainerPage), "Favorite"); break; case "MyCollect": App.AppViewModel.NavigateToSubPage(typeof(Pages_Share.Sub.Account.FavoriteContainerPage), "Collect"); break; case "ViewLater": App.AppViewModel.NavigateToSubPage(typeof(Pages_Share.Sub.Video.ViewLaterPage)); break; case "History": App.AppViewModel.NavigateToSubPage(typeof(Pages_Share.Sub.Video.HistoryPage)); break; default: break; } AccountFlyout.Hide(); }