Tips for Windows Phone 7 Development

Source: Internet
Author: User

1. Use popup to customize the pop-up effect. The pop-up blocks of the popup control are always at the front of the screen. Therefore, popup can be used to implement various pop-up boxes and provide you with a lot of custom space, many third-party pop-up box controls use popup to encapsulate various effects.

Popup method:
Private popup;
Popup = new popup ();
Popup. Child = new control class ();
// Open
Popup. isopen = true;
// Close
Popup. isopen = false

Or
XAMLCode
<Popup X: Name = "popup">
<Border>
<Stackpanel>
......
</Stackpanel>
</Border>
</Popup>

CS code
// Open
Popup. isopen = true;
// Close
Popup. isopen = false

2. Use <linebreak> </linebreak> In the textblock control to wrap the line.

<Textblock textwrapping = "Wrap">
Test
<Linebreak> </linebreak>
<Linebreak> </linebreak>
Test
<Linebreak> </linebreak>
<Linebreak> </linebreak>
Test
</Textblock>

 

3. Capture the physical button return key, open the page, and exit the page. Windows Phone has three physical buttons: Return key, start key, and search key.Program.

// Click return.
Protected override void onbackkeypress (system. componentmodel. canceleventargs E)
{
// Your code
E. Cancel = false;
Base. onbackkeypress (E );
}
// Enter the page from another page
Protected override void onnavigatedto (system. Windows. Navigation. navigationeventargs E)
{
// Your code
Base. onnavigatedto (E );
}
// Exit the current page
Protected override void onnavigatedfrom (system. Windows. Navigation. navigationeventargs E)
{
// Your code
Base. onnavigatedfrom (E );
}

4. Obtain the child control in the parent control. This method was used to determine when the ListBox control was rolled to the end.

         //  Obtain the first subtype  
Public Static T findchildoftype <t> (dependencyobject root) Where T: Class
{
VaR Queue = New Queue <dependencyobject> ();
Queue. enqueue (Root );
While (Queue. Count> 0 )
{
Dependencyobject current = queue. dequeue ();
For (Int I = visualtreehelper. getchildrencount (current )- 1 ; 0 <= I; I --)
{
VaR Child = visualtreehelper. getchild (current, I );
VaR Typedchild = Child As T;
If (Typedchild! = Null )
{
Return Typedchild;
}
Queue. enqueue (child );
}
}
Return Null ;
}

// Obtain all child types
Public Static List <t> findallchildoftype <t> (dependencyobject root) Where T: Class
{
VaR Queue = New Queue <dependencyobject> ();
Queue. enqueue (Root );
List <t> allchild = New List <t> ();
While (Queue. Count> 0 )
{
Dependencyobject current = queue. dequeue ();
For ( Int I = visualtreehelper. getchildrencount (current )- 1 ;0 <= I; I --)
{
VaR Child = visualtreehelper. getchild (current, I );
VaR Typedchild = Child As T;
If (Typedchild! = Null )
{
Allchild. Add (typedchild );
}
Queue. enqueue (child );
}
}
Return Allchild;
}

5. Use <controltemplate> ...... </Controltemplate> to extend the effects of various custom controls. When you need to implement some animation effects on the controls, alternatively, you can design a controltemplate to embed other controls on the control.

For example, you can click a button:

             <  Button  Content  = "Button"  Height  = "72"  Horizontalalignment  = "Left"  Margin  = "103,197"  Name = "Button1"  Verticalalignment  = "TOP"  Width  = "160"  > 
< Button. Template >
< Controltemplate >
< Grid Background = "Transparent" >
< Visualstatemanager. visualstategroups >
< Visualstategroup X: Name = "Commonstates" >
< Visualstate X: Name = "Pressed" >
< Storyboard >
< Objectanimationusingkeyframes Storyboard. targetname = "Buttonbackground" Storyboard. targetproperty = "Background" >
< Discreteobjectkeyframe Keytime = "0" Value = "Yellowgreen" />
</ Objectanimationusingkeyframes >
< Objectanimationusingkeyframes Storyboard. targetname = "Buttonbackground" Storyboard. targetproperty = "Borderbrush" >
< Discreteobjectkeyframe Keytime = "0" Value = "Yellowgreen" />
</ Objectanimationusingkeyframes >
</ Storyboard >
</ Visualstate >
</ Visualstategroup >
</ Visualstatemanager. visualstategroups >
< Border X: Name = "Buttonbackground" Borderbrush =" {Templatebinding borderbrush} " Borderthickness =" {Templatebinding borderthickness} " Background =" {Templatebinding background} " Margin =" {Staticresource phonetouchtargetoverhang} " >
< Contentcontrol X: Name = "Contentcontainer" Foreground =" {Templatebinding foreground} " Horizontalcontentalignment =" {Templatebinding horizontalcontentalignment} " Verticalcontentalignment =" {Templatebinding verticalcontentalignment} " Padding =" {Templatebinding padding} " Content =" {Templatebinding content} " Contenttemplate =" {Templatebinding contenttemplate} " />
</ Border >
</ Grid >
</ Controltemplate >
</ Button. Template >
</ Button >

6. Display and hide the cell phone's top tray, which is the signal and battery information on the top.
// Display
Systemtray. isvisible = true;
// Hide
Systemtray. isvisible = false;

 

A problem occurs: the height of ApplicationBar cannot be customized. When applicationbarmenuitem is an even number, there is more space below, which will affect the appearance of the image. (if it is an odd number, there will be no more space. I don't know why Microsoft wants to design it like this ), do you have any related solutions?

 

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.