Windows phone7 initiator and Selector

Source: Internet
Author: User

Learning WP7 with Mr Lin Yongjian

 

    • The windowsphone execution model determines each application.ProgramIt can only be run in its own sandbox
    • Applications cannot directly access other storage information (such as contact information ),
    • Applications cannot directly call other functions (such as phone or SMS)
    • The initiator and Selector provide applications with indirect access to these features.
    • The operating system may terminate the current application when the initiator and Selector are running.

 

 

    1. Starter: Start a built-in program for the user, and no data is returned to the called program, such as a search task.
    2. Selector: Start a built-in program for the user to use and return some data to the called program. When the user completes the operation, the program will be re-activated and the returned data will be received, if the user cancels the operation, null is returned.

WP7 built-in starters

  • Emailcomposetask -Allow users to send emails through their email accounts.
  • Marketplacedetailtask -Start Windows Phone marketplace to allow users to view a specific product.
  • Marketplacehubtask -Start Windows Phone marketplace, which allows you to display a certain type of applications by default.
  • Marketplacereviewtask -Take the user to the comment page of the current program in Windows Phone marketplace.
  • Marketplacesearchtask -Start the Windows Phone marketplace search result. The result is from the search item you enter (or the one you set ).
  • Mediaplayerlauncher -Start the built-in media player and play the specified media file.
  • Phonecalltask -Start the phone program and display the phone number and name. The call is only made after the user clicks "call.
  • Searchtask -You can regard this as a way to provide Bing search functions in your program.
  • Smscomposetask -Start the Information Program and display the function of sending information to users. You can specify the message recipient and information content, but only the user can send the message.
  • Webbrowsertask -Open the web browser and jump to the specified URL.

WP7 built-in Selector

Precautions for use of the starter:

Declare a chooser:

Photochoosertask;

New chooser instance: and register the completed event

 
Public mainpage () {initializecomponent (); photochoosertask = new photochoosertask (); photochoosertask. Completed + = new eventhandler <photoresult> (photochoosertask_completed );}

Implement the completed event:

Void photochoosertask_completed (Object sender, photoresult e) {If (E. taskresult = taskresult. OK) {MessageBox. show (E. chosenphoto. length. tostring (); system. windows. media. imaging. bitmapimage BMP = new system. windows. media. imaging. bitmapimage (); BMP. setsource (E. chosenphoto); myimage. source = BMP ;}}

Conclusion: The most obvious difference between the initiator and the selector is that the initiator does not return any information, so you do not need to register the completed event, and the selector will return some information, so you need to register the completed event, they all need to first create an instance, then configure the parameters, and finally show () can be called;

Complete backgroundCode:

Using system; using system. collections. generic; using system. LINQ; using system. net; using system. windows; using system. windows. controls; using system. windows. documents; using system. windows. input; using system. windows. media; using system. windows. media. animation; using system. windows. shapes; using Microsoft. phone. controls; using Microsoft. phone. tasks; namespace detail {public partial class mainpage: phoneapplicationpage {photochoosertask; initialize role; // constructor public mainpage () {initializecomponent (); response = new photochoosertask (); response. completed + = new eventhandler <photoresult> (photochoosertask_completed); savephonenumbertask = new savephonenumbertask (); savephonenumbertask. completed + = new eventhandler <taskeventargs> (savephonenumbertask_completed);} void savephonenumbertask_completed (Object sender, taskeventargs e) {Switch (E. taskresult) {// logic for when the number was saved successfully case taskresult. OK: MessageBox. show ("phone number saved. "); break; // logic for when the task was canceled by the user case taskresult. cancel: MessageBox. show ("Save canceled. "); break; // logic for when the number cocould not be saved case taskresult. none: MessageBox. show ("phone number cocould not be saved. "); break ;}} void photochoosertask_completed (Object sender, photoresult e) {If (E. taskresult = taskresult. OK) {MessageBox. show (E. chosenphoto. length. tostring (); system. windows. media. imaging. bitmapimage BMP = new system. windows. media. imaging. bitmapimage (); BMP. setsource (E. chosenphoto); myimage. source = BMP ;}} private void button#click (Object sender, routedeventargs e) {searchtask TaSTK = new searchtask (); TaSTK. searchquery = "littlefeihu"; TaSTK. show ();} private void button2_click (Object sender, routedeventargs e) {phonecalltask task = new phonecalltask (); task. phonenumber = "123546879"; task. displayname = "littlefeihu"; task. show ();} private void button3_click (Object sender, routedeventargs e) {photochoosertask. show ();} private void button4_click (Object sender, routedeventargs e) {try {savephonenumbertask. phonenumber = "2065550123"; savephonenumbertask. show ();} catch (system. invalidoperationexception ex) {MessageBox. show ("an error occurred. ");}}}}

previous XAML code:

<Phone: phoneapplicationpage X: class = "launchersandchoosers. mainpage "xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "xmlns: Phone =" CLR-namespace: Microsoft. phone. controls; Assembly = Microsoft. phone "xmlns: shell =" CLR-namespace: Microsoft. phone. shell; Assembly = Microsoft. phone "xmlns: D =" http://schemas.microsoft.com/expression/blend/2008 "Xmlns: MC =" http://schemas.openxmlformats.org/markup-compatibility/2006 "MC: ignorable =" D "D: designwidth =" 480 "D: designheight = "768" fontfamily = "{staticresource quota}" fontsize = "{staticresource quota}" foreground = "{staticresource quota}" supportedorientations = "portrait" orientation = "portrait" Shell: systemtray. isvisible = "true"> <! -- Layoutroot is the root grid where all page content is placed --> <grid X: Name = "layoutroot" background = "Transparent"> <grid. rowdefinitions> <rowdefinition Height = "Auto"/> <rowdefinition Height = "*"/> </grid. rowdefinitions> <! -- Titlepanel contains the name of the application and page title --> <stackpanel X: Name = "titlepanel" grid. row = "0" margin = ","> <textblock X: name = "applicationtitle" text = "" style = "{staticresource phonetextnormalstyle}"/> <textblock X: name = "pagetitle" text = "initiator and Selector" margin = "9,-7,0, 0" style = "{staticresource phonetexttitle1style}"/> </stackpanel> <! -- Contentpanel-place additional content here --> <grid X: Name = "contentpanel" grid. row = "1" margin = ","> <button content = "Search" Height = "72" horizontalalignment = "Left" margin =, 160 "name =" button1 "verticalignment =" TOP "width =" "Click =" button#click "/> <button content =" call "Height =" 72 "horizontalalignment =" left "margin =" 247,93, 160 "name =" button2 "verticalignment =" TOP "width =" "CLI Ck = "button2_click"/> <button content = "select the image" Height = "72" horizontalalignment = "Left" margin = "40,251, 160 "name =" button3 "verticalignment =" TOP "width =" "Click =" button3_click "/> <button content =" save phone "Height =" 72 "horizontalalignment =" left "margin =" 247,251, 160 "name =" button4 "verticalignment =" TOP "width =" 196 "Click =" button4_click "/> <Image Height =" 12,354 "horizontalalignment =" Left "margin =", 407 "name =" myimage "stretch =" fill "verticalignment =" TOP "width =" "/> </GRID> <! -- Sample Code showing usage of ApplicationBar --> <! -- <Phone: phoneapplicationpage. applicationBar> <shell: ApplicationBar isvisible = "true" ismenuenabled = "true"> <shell: applicationbariconbutton iconuri = "/images/appbar_button1.png" text = "button 1"/> <shell: applicationbariconbutton iconuri = "/images/appbar_button2.png" text = "button 2"/> <shell: ApplicationBar. menuitems> <shell: applicationbarmenuitem text = "menuitem 1"/> <shell: applicationbarmenuitem text = "menuitem 2"/> </shell: ApplicationBar. menuitems> </shell: ApplicationBar> </Phone: phoneapplicationpage. applicationBar> --> </Phone: phoneapplicationpage>

We can observe the application event tracking through the output window provided by Vs to facilitate ease of use.

For example, we can write the following trace code in the background:

Open the output window and F5 start debugging. For example, we track the event calling sequence and other information:

 

Code download

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.