Windows 8 Store Apps Learning (38) Contract: Search Contract

Source: Internet
Author: User
Tags xmlns

Introduced

Re-imagine the contract for Windows 8 Store Apps

Search Contract-The right-hand sidebar is called Charm, where "searching" is known as search Contract

Use search Contract to suggest that the data source is local and that you get relevant information from the Input Method Editor

Use search Contract to suggest that the data source is on the server side, as well as adding icons, descriptions, etc. for search suggestions

Use search Contract based on local file searching advice, data from file metadata

Example

1, demo Search Contract basic Application

Contracts/searchcontract/demo.xaml

<page
    x:class= "XamlDemo.Contracts.SearchContract.Demo"
    xmlns= "http://schemas.microsoft.com/winfx/ 2006/xaml/presentation "
    xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "
    xmlns:local=" using: XamlDemo.Contracts.SearchContract "
    xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "
    xmlns: Mc= "http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:ignorable= "D" >
    
    <grid background= "Transparent" >
        <stackpanel margin= "0 0 0" > <textblock name= "lblmsg" fontsize= "
    
            14.667 "text=" directly through the keyboard input can activate the Searchpane "/> <button name="
                
            btnshowsearch "content=" Open Searchpane "click=" Btnshowsearch_click_1 "margin=" 0 0 0 "/>
                
        </StackPanel>
    </Grid>
</Page>

Contracts/searchcontract/demo.xaml.cs

* * This example demonstrates the basic application of search Contract * * Search Contract-The right-hand sidebar is called Charm, where "searching" is referred to as search Contract * 1, in Package.app Xmanifest new "Search" declaration * 2, in App.xaml.cs override void Onsearchactivated (Searchactivatedeventargs args), if the App is activated by search, then You can get the relevant search information here * * Searchactivatedeventargs-when app is activated by a search event parameter * querytext-search text * previousexecutionstate- This app was searched for before activation status (Applicationexecutionstate enumeration: Notrunning, Running, suspended, terminated, Closedbyuser) * Splashscre
 En-Splash Screen Object * * Searchpane-Search panel * Getforcurrentview ()-Get the current Searchpane * Show ()-Display the search panel, if necessary, to specify the initial query string * Placeholdertext-When the search box does not enter the focus and the user does not enter any characters, the prompt text in the search box * searchhistoryenabled-whether the search suggested history feature is enabled, the default is true * Se Archhistorycontext-If the search recommended history feature is enabled, this value is used to specify the context of the history, where the history is saved and fetched, that is, the search recommendation history of an app can have multiple sets of * Showonkeyboardin Put-if keyboard input is found and the search panel is activated, the default value is False * Visible-whether the search panel is open, read-only * querychanged-Events triggered when text changes in the search box of the search panel * Qu erysubmitted-Search box to submit search panel* Visibilitychanged-Event triggered when text is turned on or off-the event triggered by opening or closing the search panel/using System;
Using Windows.ApplicationModel.Activation;
Using Windows.ApplicationModel.Search;
Using Windows.UI.Xaml;
Using Windows.UI.Xaml.Controls;
    
Using Windows.UI.Xaml.Navigation;  Namespace XamlDemo.Contracts.SearchContract {public sealed partial class Demo:page {private Searchpane
    
        _searchpane; Public Demo () {this.
        InitializeComponent (); } protected override void Onnavigatedto (NavigationEventArgs e) {//Get current Searchpane, and register phase
            Guan Event _searchpane = Searchpane.getforcurrentview ();
            _searchpane.querychanged + = _searchpane_querychanged;
    
            _searchpane.querysubmitted + = _searchpane_querysubmitted;
    
            When the search box does not enter the focus and the user does not enter any characters, the prompt text in the search box _searchpane.placeholdertext = "Please enter";
            Whether the search suggested history is enabled _searchpane.searchhistoryenabled = true; MeansThe context _searchpane.searchhistorycontext = "abc" of the historical record of the proposed search;
    
            If there is keyboard input, direct activation Searchpane _searchpane.showonkeyboardinput = true; When you activate an application by searching (see the Onsearchactivated () method in App.xaml.cs) Searchactivatedeventargs searchactivated = (searchact
            Ivatedeventargs) E.parameter;
        if (searchactivated!= null) Showsearchpane (Searchactivated.querytext);
            } protected override void Onnavigatedfrom (NavigationEventArgs e) {//Cancel monitoring of related events
            _searchpane.querychanged-= _searchpane_querychanged;
    
            _searchpane.querysubmitted-= _searchpane_querysubmitted;
        _searchpane.showonkeyboardinput = false; } private void Btnshowsearch_click_1 (object sender, RoutedEventArgs e) {Showsearchpane ()
        ;
     }//Show Search panel private void Showsearchpane (String querytext= "") {       _searchpane.show (QueryText);
        Lblmsg.text = QueryText;
            } void _searchpane_querychanged (Searchpane sender, Searchpanequerychangedeventargs args) { Lblmsg.text = args.
        QueryText;
            } void _searchpane_querysubmitted (Searchpane sender, Searchpanequerysubmittedeventargs args) { Lblmsg.text = args.
        QueryText; }
    }
}

App.xaml.cs

The method invoked when activating an application
protected override void Onsearchactivated (Searchactivatedeventargs args)
{
    if (args . Previousexecutionstate = = applicationexecutionstate.running) return
        ;
    
    var rootframe = new Frame ();
    Rootframe.navigate (typeof (MainPage), args);
    Window.Current.Content = Rootframe;
    
    Window.Current.Activate ();
}

2. This example demonstrates how to use search Contract to suggest that the data source is local. Also shows how to get relevant information from the Input Method Editor

Contracts/searchcontract/localsuggestion.xaml

<page
    x:class= "XamlDemo.Contracts.SearchContract.LocalSuggestion"
    xmlns= "http:// Schemas.microsoft.com/winfx/2006/xaml/presentation "
    xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "
    xmlns:local= "using:XamlDemo.Contracts.SearchContract"
    xmlns:d= "http://schemas.microsoft.com/ expression/blend/2008 "
    xmlns:mc=" http://schemas.openxmlformats.org/markup-compatibility/2006 "
    mc:i gnorable= "D" >
    
    <grid background= "Transparent" >
        <stackpanel margin= "0 0 0" >
    
            < TextBlock name= "lblmsg" fontsize= "14.667" text= "This example shows how to use search Contract to suggest that the data source is local. Also shows how to get relevant information from the Input Method Editor/>
                
        </StackPanel>
    </Grid>
</Page>

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.