In our last post, I explained how to create a control tilt effect application for Windows Phone 7. In this blog post, I want to share a sample that will help you to create an application bar for Windows Phone 7. This application will allow you to add the menu functionality. It also will allow you to adjust the visibility and opacity of the application bar.
I will now demonstrate how easy it is to create an application bar for Windows Phone 7, using Visual Basic for Windows Phone Developer Tools. The application bar can be created in 4 simple steps as follows:
- Create a sample application and add controls
- Add event handlers
- Build and debug the application
- Rebuild in the release mode for publishing
- Visual Studio 2010 Professional, Premium,
or Ultimate. If you do not have any of the releases, you can download any of
the following trial versions as per your preference: Professional, Premium, or Ultimate.
- Windows Phone Developer Tools
- Visual Basic
for Windows Phone Developer Tools – RTW
Note: You can install the newer version- Windows Phone Developer Tools 7.1 Beta
instead of the above mentioned two tools as it will take comparatively
less time. However, this sample was created using the previous version.
To create the application bar, let’s follow the 4 simple steps mentioned earlier:
Step 1 - Create a sample application and add controls
Create a sample application
- Create a new project and browse to the “Silverlight for Windows Phone” node.
- Select the “Windows Phone Application” template.
- Enter a name for the application.
- Click OK. The MainPage.xaml page is displayed.
- Click the MY APPLICATION text. In the Properties window, change the text property to “APPLICATION BAR SAMPLE”.
- Click the page name text. In the Properties window, change the text property to “application bar”.
- In Solution Explorer, right-click the application name and add a new folder.
- Rename the new folder as “Images”, and add the required icon images to the folder.
- To create buttons, add the following XAML code:
Your application now looks like this:
Step 2 – Add event handlers
Adding event handlers is one of the important tasks. To add the event handlers:
- Open the MainPage.xaml.vb page.
- To initialize a new instance of the ApplicationBar property, add the following code:
- To enable the menu and make the application bar visible, add the following code:
- To create event handlers for the icon button’s click event, add the following code:
- To add the icon buttons, add the following code:
- To create event handlers for the menu item’s click event, add the following code:
- To add the menu items, add the following code:
- To add the event handlers for the click events, add the following code:
Voila! Now your application bar for Windows Phone 7 is ready! You just need to build and debug the application.
Step 3 - Build and debug the application
- To build the application, select Build > Build Solution. The project should build without any errors.
- To debug the application, set the deployment target of the application to “Windows Phone 7 Emulator”.
- Select Debug > Start Debugging. The emulator window is displayed.
- To test the application in the landscape mode, select the rotation control from the edit panel.
The emulator rotates into the landscape mode and accordingly, the controls resize themselves to fit the screen.
Note: To stop debugging the application, select Debug > Stop Debugging.
Step 4 - Rebuild in the release mode for publishing
- On the standard toolbar, change the configuration manager to Release.
- To rebuild the application, select Build > Rebuild. The XAP file of the application is generated.
Finally, to submit your application to the market place, you can refer to upload your application walkthrough.
That’s it! We’ve now seen that creating an application bar for Windows Phone 7 isn’t that tough. In fact, you’ve created it in just 4 simple steps!
You can find the full source code for the Visual Basic application bar for Windows Phone 7 here.