Example #1
0
        //Providing search suggestions - creates a self populated list from the dogs.txt file
        void OnSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args)
        {
            Dictionary <string, List <BreedDataItem> > _results = new Dictionary <string, List <BreedDataItem> >();
            List <string> termList = new List <string>();
            var           groups   = BreedDataSource.GetGroups("AllGroups");
            string        query    = args.QueryText.ToLower();
            var           all      = new List <BreedDataItem>();

            _results.Add("All", all);

            foreach (var group in groups)
            {
                var items = new List <BreedDataItem>();
                _results.Add(group.ShortTitle, items);

                foreach (var item in group.Items)
                {
                    termList.Add(item.ShortTitle.ToLower());
                }
            }
            foreach (var term in termList)
            {
                if (term.StartsWith(query.ToLower()))
                {
                    args.Request.SearchSuggestionCollection.AppendQuerySuggestion(term);
                }
            }
        }
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            // TODO: Create an appropriate data model for your problem domain to replace the sample data
            var BookDataGroups = BreedDataSource.GetGroups((String)navigationParameter);

            this.DefaultViewModel["Groups"] = BookDataGroups;
        }
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            // TODO: Create an appropriate data model for your problem domain to replace the sample data
            var group = BreedDataSource.GetGroup((String)navigationParameter);

            this.DefaultViewModel["Group"] = group;
            this.DefaultViewModel["Items"] = group.Items;

            //register for data request events
            DataTransferManager.GetForCurrentView().DataRequested += OnDataRequested;
        }
Example #4
0
        /// <summary>
        /// Invoked when the application is activated to display search results.
        /// </summary>
        /// <param name="args">Details about the activation request.</param>
        protected async override void OnSearchActivated(Windows.ApplicationModel.Activation.SearchActivatedEventArgs args)
        {
            if (args.PreviousExecutionState == ApplicationExecutionState.NotRunning || args.PreviousExecutionState == ApplicationExecutionState.ClosedByUser || args.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                await BreedDataSource.LoadDataAsync();

                SearchPane.GetForCurrentView().SuggestionsRequested += OnSuggestionsRequested;
            }


            // TODO: Register the Windows.ApplicationModel.Search.SearchPane.GetForCurrentView().QuerySubmitted
            // event in OnWindowCreated to speed up searches once the application is already running

            // If the Window isn't already using Frame navigation, insert our own Frame
            var previousContent = Window.Current.Content;
            var frame           = previousContent as Frame;

            // If the app does not contain a top-level frame, it is possible that this
            // is the initial launch of the app. Typically this method and OnLaunched
            // in App.xaml.cs can call a common method.
            if (frame == null)
            {
                // Create a Frame to act as the navigation context and associate it with
                // a SuspensionManager key
                frame = new Frame();
                FriendsWithPaws.Common.SuspensionManager.RegisterFrame(frame, "AppFrame");

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Restore the saved session state only when appropriate
                    try
                    {
                        await FriendsWithPaws.Common.SuspensionManager.RestoreAsync();
                    }
                    catch (FriendsWithPaws.Common.SuspensionManagerException)
                    {
                        //Something went wrong restoring state.
                        //Assume there is no state and continue
                    }
                }
            }

            frame.Navigate(typeof(SearchResultsPage), args.QueryText);
            Window.Current.Content = frame;

            // Ensure the current window is active
            Window.Current.Activate();
        }
Example #5
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            // Allow saved page state to override the initial item to display
            if (pageState != null && pageState.ContainsKey("SelectedItem"))
            {
                navigationParameter = pageState["SelectedItem"];
            }

            // TODO: Create an appropriate data model for your problem domain to replace the sample data
            var item = BreedDataSource.GetItem((String)navigationParameter);

            this.DefaultViewModel["Group"] = item.Group;
            this.DefaultViewModel["Items"] = item.Group.Items;
            this.flipView.SelectedItem     = item;

            DataTransferManager.GetForCurrentView().DataRequested += OnDataRequested;
        }
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            var queryText = navigationParameter as String;

            // TODO: Application-specific searching logic.  The search process is responsible for
            //       creating a list of user-selectable result categories:
            //
            //       filterList.Add(new Filter("<filter name>", <result count>));
            //
            //       Only the first filter, typically "All", should pass true as a third argument in
            //       order to start in an active state.  Results for the active filter are provided
            //       in Filter_SelectionChanged below.

            var filterList = new List <Filter>();

            filterList.Add(new Filter("All", 0, true));

            var    groups = BreedDataSource.GetGroups("AllGroups");
            string query  = queryText.ToLower();
            var    all    = new List <BreedDataItem>();

            _results.Add("All", all);

            foreach (var group in groups)
            {
                var items = new List <BreedDataItem>();

                _results.Add(group.Title, items);

                foreach (var item in group.Items)
                {
                    if (item.Title.ToLower().Contains(query) || item.Description.ToLower().Contains(query))
                    {
                        all.Add(item);
                        items.Add(item);
                    }
                }
                filterList.Add(new Filter(group.Title, items.Count, false));
            }
            filterList[0].Count = all.Count;

            // Communicate results through the view model
            this.DefaultViewModel["QueryText"]   = '\u201c' + queryText + '\u201d';
            this.DefaultViewModel["Filters"]     = filterList;
            this.DefaultViewModel["ShowFilters"] = filterList.Count > 1;
        }
Example #7
0
        void OnSuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args)
        {
            string Queryable = args.QueryText.ToLower(); //grabs text
            string groups    = BreedDataSource.GetGroup(Queryable).ShortTitle;


            List <String> termList = null; //makes list

            //grabs data
            termList.Add(groups);
            foreach (string item in termList)
            {
                if (item.StartsWith(Queryable))
                {
                    args.Request.SearchSuggestionCollection.AppendQuerySuggestion(item);
                }
            }
        }
Example #8
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="args">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs args)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active

            if (args.PreviousExecutionState == ApplicationExecutionState.Running)
            {
                if (!String.IsNullOrEmpty(args.Arguments))
                {
                    ((Frame)Window.Current.Content).Navigate(typeof(ItemDetailPage), args.Arguments);
                }
                Window.Current.Activate();
                return;
            }

            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                //Associate the frame with a SuspensionManager key
                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Restore the saved session state only when appropriate
                    try
                    {
                        await SuspensionManager.RestoreAsync();
                    }
                    catch (SuspensionManagerException)
                    {
                        //Something went wrong restoring state.
                        //Assume there is no state and continue
                    }
                }

                if (args.PreviousExecutionState == ApplicationExecutionState.Running)
                {
                    Window.Current.Activate();
                    return;
                }
                await BreedDataSource.LoadDataAsync();

                SearchPane.GetForCurrentView().SuggestionsRequested += OnSuggestionsRequested;
                // Place the frame in the current Window
                Window.Current.Content = rootFrame;

                if (!String.IsNullOrEmpty(args.Arguments))
                {
                    rootFrame.Navigate(typeof(ItemDetailPage), args.Arguments);
                    Window.Current.Content = rootFrame;
                    Window.Current.Activate();
                    return;
                }
            }
            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (!rootFrame.Navigate(typeof(GroupedItemsPage), "AllGroups"))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }