Windows Phone development (24): sending text messages between the initiator and Selector

Source: Internet
Author: User

In this section, we use a simple text message sending example to demonstrate how to use the phonenumberchoosertask and smscomposetask classes together.

Phonenumberchoosertask is a selector used to select the phone number from your phone book for sending text messages;

Smscomposetask is used to start the SMS sending component and display the sending window.

Note: These operations are all under the control of the user, and the visual page will be displayed when you send text messages without secretly sending them in the background, because Windows Phone is based on the user experience and security, sending in the background is not allowed, and the sending process is controlled by the user. You can choose to cancel or exit.

The to attribute of the smscomposetask class is the target phone number, and the body is the body of the text message you want to send.

Similarly, you can easily complete this task. If you don't believe it, check the code.

<Phone: phoneapplicationpage <br/> X: class = "smssample. mainpage "<br/> xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "<br/> xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "<br/> xmlns: Phone =" CLR-namespace: Microsoft. phone. controls; Assembly = Microsoft. phone "<br/> xmlns: shell =" CLR-namespace: Microsoft. phone. shell; Assembly = Microsoft. phone "<br/> xmlns: D =" http://schemas.microsoft. COM/expression/blend/2008 "<br/> xmlns: MC =" http://schemas.openxmlformats.org/markup-compatibility/2006 "<br/> MC: ignorable =" D "D: designwidth =" 480 "D: designheight = "768" <br/> fontfamily = "{staticresource phonefontfamilynormal}" <br/> fontsize = "{staticresource quota}" <br/> foreground = "{staticresource phoneforegroundbrush} "<br/> supportedorientations =" portrait "orientation =" portrait "<B R/> shell: systemtray. isvisible = "true"> </P> <p> <! -- Layoutroot is the root mesh that contains all page content --> <br/> <grid X: Name = "layoutroot" background = "Transparent"> <br/> <grid. rowdefinitions> <br/> <rowdefinition Height = "Auto"/> <br/> <rowdefinition Height = "*"/> <br/> </grid. rowdefinitions> </P> <p> <! -- Titlepanel contains the application name and page title --> <br/> <stackpanel X: Name = "titlepanel" grid. row = "0" margin = ","> <br/> <textblock X: name = "applicationtitle" text = "my application" style = "{staticresource phonetextnormalstyle}"/> <br/> <textblock X: name = "pagetitle" text = "send SMS" margin = "9,-7,0, 0 "style =" {staticresource phonetexttitle1style} "/> <br/> </stackpanel> </P> <p> <! -- Contentpanel-place other content here --> <br/> <grid X: Name = "contentpanel" grid. row = "1" margin = "12, 0, 12, 0"> <br/> <textblock Height = "40" horizontalalignment = "Left" margin = "33,69, 0, 0 "name =" textblock1 "text =" receiver: "verticalalignment =" TOP "fontsize =" 30 "width =" 144 "/> <br/> <textbox Height =" 72 "horizontalalignment =" Left "margin =" 12,116, 418 "name =" txtphonenumber "text =" "verticalalignment =" TOP "width =" "> <br/> <textbox. inputscope> <br/> <inputscopename namevalue = "Number"/> <br/> </inputscope> <br/> </textbox. inputscope> <br/> </textbox> <br/> <textblock fontsize = "30" Height = "40" horizontalalignment = "Left" margin = "33,235, 0, 0 "name =" textblock2 "text =" text message content: "verticalalignment =" TOP "width =" 213 "/> <br/> <textbox Height =" 233 "horizontalalignment =" Left "margin =" 12,283, 418 "name =" txtmessage "text =" "verticalalignment =" TOP "width =" "textwrapping =" Wrap "/> <br/> <button content =" send "height = "79" horizontalalignment = "Left" margin = "48,522, 357 "name =" btnsend "verticalignment =" TOP "width =" "Click =" btnsend_click "/> <br/> <button content =" Select phone number "Height =" 72 "horizontalalignment =" Left "margin =" 185, 45, 220 "name =" btnchoose "verticalignment =" TOP "width =" "Click =" btnchoose_click "/> <br/> </GRID> </P> <p> </phone: phoneapplicationpage>

Using system; <br/> using system. collections. generic; <br/> using system. LINQ; <br/> using system. net; <br/> using system. windows; <br/> using system. windows. controls; <br/> using system. windows. documents; <br/> using system. windows. input; <br/> using system. windows. media; <br/> using system. windows. media. animation; <br/> using system. windows. shapes; <br/> using Microsoft. phone. controls; </P> <p> using Microsoft. Phone. tasks; </P> <p> namespace smssample <br/> {<br/> Public partial class mainpage: phoneapplicationpage <br/>{< br/> phonenumberchoosertask mychooser = new phonenumberchoosertask (); <br/> smscomposetask SMS = NULL; </P> <p> // constructor <br/> Public mainpage () <br/>{< br/> initializecomponent (); <br/> // instantiate <br/> SMS = new smscomposetask (); <br/> // register a callback event <br/> mychooser. completed + = (sender, e) => {<Br/> If (E. taskresult = taskresult. OK) <br/>{< br/> dispatcher. begininvoke () => {this.txt phonenumber. TEXT = E. phonenumber ;}); <br/>}< br/> }; <br/>}</P> <p> // select a contact <br/> private void btnchoose_click (Object sender, routedeventargs E) <br/>{< br/> If (mychooser = NULL) <br/>{< br/> mychooser = new phonenumberchoosertask (); <br/>}< br/> mychooser. show (); <br/>}</P> <p> // send <br/> priv Ate void btnsend_click (Object sender, routedeventargs e) <br/>{< br/> If (txtphonenumber. TEXT = "" | txtmessage. TEXT = "") <br/>{< br/> MessageBox. show ("the recipient number and text message content cannot be blank. "); <Br/> return; <br/>}< br/> If (SMS = NULL) <br/>{< br/> SMS = new smscomposetask (); <br/>}< br/> // value assignment <br/> SMS. to = txtphonenumber. text; <br/> SMS. body = txtmessage. text; </P> <p> try <br/> {<br/> SMS. show (); <br/>}< br/> catch (exception ex) <br/>{< br/> MessageBox. show (ex. message); <br/>}< br/>}

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.