Beispiel #1
0
        /// <summary>
        /// Determines how best to support navigation back to the previous application state.
        /// </summary>
        public static void Activate(String queryText, ApplicationExecutionState previousExecutionState)
        {
            UIElement previousContent = Window.Current.Content;
            var       frame           = previousContent as Frame;

            if (frame != null)
            {
                // If the app is already running and uses top-level frame navigation we can just
                // navigate to the search results
                frame.Navigate(typeof(SearchResultsPage), queryText);
            }
            else
            {
                // Otherwise bypass navigation and provide the tools needed to emulate the back stack
                var page = new SearchResultsPage
                {
                    _previousContent = previousContent, _previousExecutionState = previousExecutionState
                };
                page.LoadState(queryText, null);
                Window.Current.Content = page;
            }

            // Either way, active the window
            Window.Current.Activate();
        }
        /// <summary>
        /// Invoked when the application is activated to display search results.
        /// </summary>
        /// <param name="args">Details about the activation request.</param>
        protected override void OnSearchActivated(SearchActivatedEventArgs args)
        {
            if (DataSource == null)
            {
                DataSource = new SampleDataSource();
                Windows.ApplicationModel.Search.SearchPane.GetForCurrentView().QuerySubmitted +=
                    (sender, queryArgs) => SearchResultsPage.Activate(queryArgs.QueryText, args.PreviousExecutionState);
                var previousContent = Window.Current.Content;
                var frame           = previousContent as Frame;

                if (frame == null)
                {
                    frame = new Frame();
                    Window.Current.Content = frame;
                }

                frame.Navigate(typeof(SearchResultsPage), new Tuple <String, UIElement>(args.QueryText, previousContent));
                Window.Current.Activate();
            }
            else
            {
                SearchResultsPage.Activate(args.QueryText, args.PreviousExecutionState);
            }
        }