Logo
HOW TO
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
 
 
Windows Phone

Windows Phone 7 : The Silverlight Controls (part 6) - Interactive Controls - ApplicationBar Controls

1/20/2014 2:02:36 AM
2.7. ApplicationBar Controls

The ApplicationBar is responsible for displaying the small toolbars that are often seen at the bottom of the screen. It can hold up to a maximum of four image-based application buttons, and also a potentially unlimited number of menu items. These can be used to offer access to common features within your game (getting help, showing the scores, starting a new game, and so on).

The ApplicationBar is not added to the page from the Toolbox, but rather it already exists as a property of the PhoneApplicationPage object that forms the basis for all the pages within Silverlight. To add an ApplicationBar, we therefore need to set the PhoneApplicationPage.ApplicationBar property to a new instance of the ApplicationBar class.

This can be achieved using code along the lines of that shown in Listing 9. This should be added to the XAML at the very end of the code, just before the closure of the root phone:PhoneApplicationPage element.

Example 9. A template for an ApplicationBar
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar>
<shell:ApplicationBarIconButton IconUri="/Images/AppBarButton1.jpg" Text="Button 1"/>
<shell:ApplicationBarIconButton IconUri="/Images/AppBarButton2.jpg" Text="Button 2"/>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="MenuItem 1"/>


<shell:ApplicationBarMenuItem Text="MenuItem 2"/>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

This code produces an ApplicationBar that in its default state looks like the one shown in Figure 11.

Figure 11. The ApplicationBar in its default closed state

Tapping the ellipsis button on the right edge of the ApplicationBar will cause it to open, revealing the text for each of the buttons and the menu items hidden beneath (see Figure 12). Note that Silverlight has automatically set the text for the buttons and menu items into lowercase; this is the standard behavior across all Windows Phone 7 application bars and cannot be changed.

Figure 12. The ApplicationBar in its open state

To add more buttons, simply add additional instances if the ApplicationBarIconButton class (or indeed, remove the instances that are already there to show less buttons).

The IconUri property of each button is shown referencing an image file within the Images folder. These image paths must be entered manually because there is no Properties window editor to help you to select them.

NOTE

When adding ApplicationBar icon images to your project, it is essential that their Build Action be set to Content. If they are left with the more usual (and default) Resource, they will simply appear as broken image icons when your project is run.

Images should be created at 48 × 48 pixels and should be created so that they have a white foreground on a transparent background (using the alpha channel to enforce the transparency). The circle that can be seen displayed around the icons is added automatically and should not be part of the image. To allow for this circular outline, the icon should be restricted to the 26 × 26 pixel region in the centre of the provided image.

Microsoft helpfully provides a small library of useful image files as part of the Windows Phone 7 SDK. You can find them in your Program Files directory (or Program Files (x86) on 64-bit installations of Windows) inside the Microsoft SDKs\Windows Phone\v7.0\Icons\dark directory.


Buttons can be enabled or disabled using their IsEnabled property. When the user taps one of the buttons, its Click event will be fired.

Menu items can be added or removed as required by providing an appropriate number of ApplicationBarMenuItem objects. Microsoft recommends a maximum of five menu items to prevent the user having to scroll, but more than this can be added if required. Each menu item also has an IsEnabled property and a Click event.

The ApplicationBar also has several properties that can be used to control its appearance and function. The most useful of these are the IsVisible and Opacity properties.

Setting IsVisible to false will fairly predictably cause the menu to disappear.

The Opacity property has some more subtle behavior, however. When set to 1 (its default), it reserves some space from the page for itself, pushing the content above up and out of the way. Setting to any lower value than this will cause its background (though not the buttons themselves) to become less and less opaque, but will also cause it to stop reserving space within the page. The bar will therefore appear in front of any other page content that occupies the bottom area of the screen.

With an Opacity less than 1, the ApplicationBar will be placed in front of any other content in the bottom of the page, but will still receive all screen taps in that area even with an Opacity of 0. Ensure that there is never anything behind the ApplicationBar that the user will want to interact with because they will be unable to do so.


Figure 13 shows three pictures of an ApplicationBar. It is contained on a page that has a large Image control aligned to its bottom. The picture on the left has the Opacity property set to 1. Notice that it has pushed the Image up and out of the way. The pictures in the middle and on the right have Opacity values of 0.5 and 0, respectively. The background transparency has clearly changed, but you can also see that the Image is now appearing behind the ApplicationBar rather than above it.

Figure 13. ApplicationBars with varying levels of Opacity
Other -----------------
- Windows Phone 7 : The Silverlight Controls (part 1) - Display Controls -TextBlock Controls, Image Controls, ProgressBar Controls
- Windows Phone 8 : Using Sound (part 2) - Recording Sounds
- Windows Phone 8 : Using Sound (part 1) - Playing Sounds with MediaElement, Using XNA Libraries, Playing Sounds with XNA, Adjusting Playback
- Windows Phone 8 : Localizing Your Phone Application
- Windows Phone 7 : Running Silverlight Projects in the Browser (part 2)
- Windows Phone 7 : Running Silverlight Projects in the Browser (part 1)
- Windows Phone 7 : Running XNA Projects in Windows (part 5)
- Windows Phone 7 : Running XNA Projects in Windows (part 4) - Converting the Game Framework to Run on Windows
- Windows Phone 7 : Running XNA Projects in Windows (part 3) - Input Differences, Isolated Storage, Application Life Cycle
- Windows Phone 7 : Running XNA Projects in Windows (part 2) - Display Differences
 
 
REVIEW
- First look: Apple Watch

- 10 Amazing Tools You Should Be Using with Dropbox

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
 
VIDEO TUTORIAL
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
 
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
Popular keywords
HOW TO Swimlane in Visio Visio sort key Pen and Touch Creating groups in Windows Server Raid in Windows Server Exchange 2010 maintenance Exchange server mail enabled groups Debugging Tools Collaborating
Top 10
- Microsoft Excel : How to Use the VLookUp Function
- Fix and Tweak Graphics and Video (part 3) : How to Fix : My Screen Is Sluggish - Adjust Hardware Acceleration
- Fix and Tweak Graphics and Video (part 2) : How to Fix : Text on My Screen Is Too Small
- Fix and Tweak Graphics and Video (part 1) : How to Fix : Adjust the Resolution
- Windows Phone 8 Apps : Camera (part 4) - Adjusting Video Settings, Using the Video Light
- Windows Phone 8 Apps : Camera (part 3) - Using the Front Camera, Activating Video Mode
- Windows Phone 8 Apps : Camera (part 2) - Controlling the Camera’s Flash, Changing the Camera’s Behavior with Lenses
- Windows Phone 8 Apps : Camera (part 1) - Adjusting Photo Settings
- MDT's Client Wizard : Package Properties
- MDT's Client Wizard : Driver Properties
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro