Quick build of Windows 8 style application 13-SearchContract

Source: Internet
Author: User

This blog post mainly introduces how to build SearchContract in applications. The principles have been clearly stated in blog 12-SearchContract for quick building of Windows 8 style applications and its principles.

How to Build SearchContract in applicationsThe following describes how to build a Search Contract: Set Application Search Permission:Before building SearchContract in an application, make sure that the application has the corresponding Search capability. You can view the settings in the Application List file. 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F9564H3-0.png "/> Add standard Search Contract Page:Add the Search Contract page to the application solution. 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F95CK9-1.png "/> View Search Contract The default control template generated on the page:After the SearchResultPage. xaml page is added, a control template for displaying search information on the page is automatically created. Example: 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F95A1W-2.png "/> the appropriate XAML designer display style: 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F95B449-3.png "/> Search Contract Page Corresponding cs File LoadState Method:In the LoadState method of the SearchResultPage. xaml. cs file, search application data based on the search text and add it to the dataset. The code can be as follows: 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F95A150-4.png "/> Change Search Contract Data template to be bound to the page:In the solution, change the StandardSmallIcon300x70ItemTemplate data template of the StandardStyles. xaml file in the Common folder and set the field control to be displayed in the data template. Example: 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F9562E7-5.png "/> Run the application to view the search results:Here we can use Search Contract to Search information and display the Search results on the added Search Contract page. Result 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F9563Y2-6.png "/> the above shows how to search when the application is running, in fact, applications can be started and searched through Search Contract when they are disabled. External startup of the application:In App. xaml. csFile, which needs to be overwritten OnSearchActivated Method to receive search activation events sent by the system. OnSearchActivated The method is triggered in two cases: Search Contract Click Search Button and click an application in the list. OnSearchActivated Method. The Code is as follows:650) this. length = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F95A624-7.png "/> in the code, first determine whether the current application status is" NotRunning "," ClosedByUser "," Terminated ", if it is one of the three statuses, load the data first, register the SuggestionRequested search suggestion) event, and finally activate the SearchResultPage page. Note:You can set the PlaceholderText attribute value of the GetForCurrentView () method of the SearchPane class to customize the prompt text in the Search Contract panel input box and tell the user what to enter for Search, when the text is entered, the prompt text will automatically disappear. The code can be as follows; 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F9562119-8.png "/> effect: 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F9562924-9.png "/> Asynchronous search recommendations:As mentioned in the previous blog, developers must provide search suggestions when users enter search information to improve user experience. So how to implement search recommendations in applications? Register Search Contract Panel search suggestion event:650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F9561149-10.png "/> Search recommendations for matching in the OnSuggestionsRequested method. 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F9563R6-11.png "/> code AppendQuerySuggestion ()Method implementation provides search recommendations. Note:Pass AppendQuerySuggestion ()You can add all the information of an array to the search suggestion, but the current search panel displays a maximum 5Search recommendations, which need to be noticed by developers during the development process. Effect 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F95B102-12.png "/> WE CAN ALSO AppendSearchSeparator ()Method to provide necessary columns in the search suggestion. Code: 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F9562O6-13.png "/> effect: 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F95A2W-14.png "/> In addition, Search Contract provides Search recommendationsYou can directly jump to the details page of the corresponding information. To achieve search recommendations, you need to use SearchSuggestionCollection Class AppendResultSuggestion (String text, string detailText, string tag, IRandomAccessStreamReference image, string imageAlternateText)Method. The code can be as follows: 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F95BM2-15.png "/> In the code AppendResultSuggestion() The parameters in the method are as follows: 1. text and detaiText are the information recommended for search; 2. tag is a unique tag, which is clicked by the user. ResultSuggestionTrigger ReslutionSuggestionChosenThe information received by the program during the event, so that the corresponding results can be displayed on the page; 3. image is the image recommended for search; 4. imageAlternateText is the additional information of the image, which is not displayed in the search Panel; effect: 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F9561564-16.png "/> AppendQuerySuggestion ()Method and AppendResultSuggestion() Main differences: 1. appendQuerySuggestion mainly tells the user the suggestion for searching information, and AppendResultSuggestion mainly tells the user the result that may be searched; 2. appendQuerySuggestion only contains text information, AppendResultSuggestion contains image, title, detailtitle, and other information; 3. appendResultSuggestion allows you to directly navigate to a detailed page of information; Local Search recommendations: Set SearchPaneOf LocalContentSuggestionSettingsAnd cancel OnSuggestionsRequestedEvent listening, which provides recommendations for searching local files. Where LocalContentSuggestionSettingsClass contains the search range, path, and file format. The code can be as follows: 650) this. width = 650; "border =" 0 "alt =" "src =" http://img1.51cto.com/attachment/201209/144639303.png "/> LocalContentSuggestionSettingsFor more information about class methods and attributes, see MSDN: LocalContentSuggestionSettings class. Note: To search for a local file, you must Configuration FileTo enable the read permission for data. Example: 650) this. width = 650; "border =" 0 "alt =" "src =" http://img1.51cto.com/attachment/201209/144658272.png "/> Set search history:After using our application for a long time, the system history will become very lengthy. You can use the following code to disable history: 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F9561617-19.png "/> there is also an attribute about search history: SearchHistoryContext. First, we need to know which historical records can be used through the SearchHistoryContext attribute.

This article is from the "Wang Zukang" blog, please be sure to keep this source http://wzk89.blog.51cto.com/1660752/1007330

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.