Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Phone

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

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
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
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server