예제 #1
0
 private async void Results_ItemClick(object sender, ItemClickEventArgs e)
 {
     await App.Current.Navigate(typeof(MainPage), LibraryItemToken.GetSingleUseToken((ILibraryItem)e.ClickedItem));
 }
예제 #2
0
        /// <summary>
        /// Like OnNavigatedTo(), but runs after the whole UI has already been prepared.
        /// Place any loading code here that requires the UI to be completely loaded.
        /// </summary>
        private async void page_Loaded(object sender, RoutedEventArgs e)
        {
            // Initialize the controller if necessary
            if (AudioController.Default.Status == AudioControllerStatus.NotReady)
            {
                DependencyObject rootGrid         = Windows.UI.Xaml.Media.VisualTreeHelper.GetChild(Window.Current.Content, 0);
                MediaElement     rootMediaElement = (MediaElement)Windows.UI.Xaml.Media.VisualTreeHelper.GetChild(rootGrid, 0);
                AudioController.Default.Ready(rootMediaElement);
            }

            // Initialize animations
            VisualStateManager.GoToState(this, "NoOverlayAlbum", false);
            VisualStateManager.GoToState(this, "NoOverlayQueue", false);
            VisualStateManager.GoToState(this, "NoOverlayMessage", false);

            Type            pageMode            = typeof(Album);
            double          scroll              = 0d;
            ITrackContainer navigationContainer = null;
            Track           navigationItem      = null;

            if (_navigationParameter.HasValue && LibraryItemToken.VerifyToken(_navigationParameter.Value))
            {
                var navigationParameter = LibraryItemToken.GetItem(_navigationParameter.Value);

                // If there is a navigationParameter, use it, and ignore the pageState!
                if (navigationParameter is Album)
                {
                    pageMode            = typeof(Album);
                    navigationContainer = navigationParameter as ITrackContainer;
                }
                else if (navigationParameter is Playlist)
                {
                    pageMode            = typeof(Playlist);
                    navigationContainer = navigationParameter as ITrackContainer;
                }
                else if (navigationParameter is Track)
                {
                    pageMode       = typeof(Album);
                    navigationItem = navigationParameter as Track;
                    if (navigationItem != null)
                    {
                        navigationContainer = navigationItem.ContainingAlbum;
                    }
                }
            }
            else if (_pageState != null)
            {
                // If no navigationParameter but pageState available, modify UI according to pageState
                if (_pageState.ContainsKey("PageMode"))
                {
                    pageMode = Type.GetType((string)_pageState["PageMode"]);
                }

                if (_pageState.ContainsKey("AlbumScroll"))
                {
                    scroll = (double)_pageState["AlbumScroll"];
                }
            }

            PageMode             = pageMode;
            _pageState           = null;
            _navigationParameter = null;

            if (navigationContainer != null)
            {
                IsAlbumOverlayShown = true;

                // Delay scrolling after animation
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    CurrentSelection = navigationContainer;
                    albumGridView.ScrollIntoView(CurrentSelection);

                    if (navigationItem != null)
                    {
                        albumDetailListView.SelectedIndex = navigationContainer.IndexOf(navigationItem);
                        albumDetailListView.ScrollIntoView(albumDetailListView.SelectedItem);
                    }
                });
            }
            else if (scroll > double.Epsilon)             // Don't scroll if scroll is negative or less than Epsilon
            {
                // Delay scrolling after animation
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    FindVisualChild <ScrollViewer>(albumGridView).ScrollToHorizontalOffset(scroll);
                });
            }
        }