Add application bar
It is intuitive to use expression blend.
Add application bar: Right-click the phoneapplicationpage on the objects and Timeline panel and select Add ApplicationBar.
Add applicationbariconbutton: Right-click ApplicationBar and select Add applicationbariconbutton.
Add applicationbarmenuitem: Right-click ApplicationBar and select Add applicationbarmenuitem. (The following uses iconbutton as an example. menuitem is similar to this one)
Attribute panel of applicationbariconbutton:
Name. The search column is used to search for attributes. However, the attributes of applicationbariconbutton are too few and are displayed below.
Many built-in Button icons can be found in the iconuri drop-down box ,... You can customize the icon file path.
Text is: Touch the right... When the icon button is displayed, the introductory text below each icon is displayed.
To add an event, select the Panel on which lightning is located in the upper-right corner and double-click it in the text box next to click.
Setting one by one is troublesome. Therefore, use a loop to bind the click events of each menu item:
Using Microsoft. Phone. Shell; Make applicationbarmenuitem visible
Foreach (applicationbarmenuitem menuitem in this. ApplicationBar. menuitems)
{
Menuitem. Click + = new eventhandler (applicationbarmenuitem_click );
}
In applicationbarmenuitem_click, convert the sender type to applicationbarmenuitem to get different attribute values.
Author'sCodeThe interface iapplicationbarmenuitem is used instead of the specific applicationbarmenuitem class. The reason is that Microsoft's WP team is more flexible for future expansion, but we don't need to care about it here.
Applicationbariconbutton Initialization
The applicationbariconbutton control cannot be initialized only when it is in XAML.
// Assign application bar buttons to member fields, because this cannot be done by initializecomponent:
This. sosbutton = This. ApplicationBar. Buttons [0] As applicationbarmenuitem;
This. strobebutton = This. ApplicationBar. Buttons [1] As applicationbarmenuitem;
In the source code of the author, all images are stored in the images directory. However, when you use blend to add images, the icons directory is automatically created. Therefore, it is better to put images in the icons directory.
The MessageBox of Windows Phone is simplified. There are only two buttons, and the button text cannot be customized. To customize MessageBox, Microsoft. xNa. Framework. gamerservices is required. For details, see page 58.