F5 Debug…

Building & Debugging the Technology!!!

Learn Windows Phone 7 Development in 31 Days

Posted by Karthikeyan Anbarasan on January 30, 2012

Welcome to the 31 Days of Windows Phone 7 Development (Mango Edition). Each day in the month of February 2012 we are going to see a topic on Windows Phone 7 development. These topics will range from level 100 to level 400 for Novice to Professionals to gets ideas on Windows Phone 7 application development and deployment to the Market Place with ease, to pass all the certification check lists that should be followed.

Each day you can expect the article to be published by 7:00 AM IST. Members can subscribe to the series and get the article directly to the subscribed mail id for easy accessibility. This page will be the HOME Page to access the articles list, each day when an article is published the respective day’s tile will be enabled and you can navigate to the respective article.

Readers can download the article source code and the article as pdf for offline reading from the options provided at the top of each article that are going to be published. In the list below, I have covered almost all the major topics which are required to develop an application with Windows Phone SDK 7.1(Mango). If you feel any other topic that will be useful but missing here, do leave me a comment so that I can include it as well.

Windows Phone 7 Articles

Getting Started with Windows Phone 72 Hello World3 Expression Blend4 Application Bar5 Alarms6 Contacts7 Calendar8 Camera9 Panaroma10 Pivot11 Media12 Toast Notification13 Tile Notification14 Raw Notification15 Tiles16 Launchers17 Choosers18 Navigation19 Web Browser20 Orientations21 BING Map22 Device Info23 Themes24 Isolated Storage25 Files and Folders26 Local Database27 OData Service28 WCF Service29 Security30 WP7 Tool Kit31 Market Place

Titles:

Learn Windows Phone 7 Development in 31 Days – Day 1 – Overview and Requirements of WP7
Learn Windows Phone 7 Development in 31 Days – Day 2 – Creating a Hello World Silverlight Application in WP7
Learn Windows Phone 7 Development in 31 Days – Day 3 – Using Expression Blend to Design the WP7 Application
Learn Windows Phone 7 Development in 31 Days – Day 4 – Working with Application Bar in WP7
Learn Windows Phone 7 Development in 31 Days – Day 5 – Working with Alarms/Reminders in WP7
Learn Windows Phone 7 Development in 31 Days – Day 6 – Working with Contacts in WP7
Learn Windows Phone 7 Development in 31 Days – Day 7 – Working with Calendar in WP7
Learn Windows Phone 7 Development in 31 Days – Day 8 – Working with Camera in WP7
Learn Windows Phone 7 Development in 31 Days – Day 9 – Working with Panorama Control in WP7
Learn Windows Phone 7 Development in 31 Days – Day 10 – Working with Pivot Application Control in WP7
Learn Windows Phone 7 Development in 31 Days – Day 11 – Working with Media in WP7
Learn Windows Phone 7 Development in 31 Days – Day 12 – Working with Toast Notification in WP7
Learn Windows Phone 7 Development in 31 Days – Day 13 – Working with Tile Notification in WP7
Learn Windows Phone 7 Development in 31 Days – Day 14 – Working with Raw Notification in WP7
Learn Windows Phone 7 Development in 31 Days – Day 15 – Working with Tiles in WP7
Learn Windows Phone 7 Development in 31 Days – Day 16 – Working with Launchers in WP7
Learn Windows Phone 7 Development in 31 Days – Day 17 – Working with Choosers in WP7
Learn Windows Phone 7 Development in 31 Days – Day 18 – Working with Navigation in WP7
Learn Windows Phone 7 Development in 31 Days – Day 19 – Working with Web Browser Control in WP7
Learn Windows Phone 7 Development in 31 Days – Day 20 – Working with Screen Orientation in WP7
Learn Windows Phone 7 Development in 31 Days – Day 21 – Working with BING Map Control in WP7
Learn Windows Phone 7 Development in 31 Days – Day 22 – Working with Device Information in WP7
Learn Windows Phone 7 Development in 31 Days – Day 23 – Working with Themes in WP7
Learn Windows Phone 7 Development in 31 Days – Day 24 – Working with Isolated Storage’s in Wp7
Learn Windows Phone 7 Development in 31 Days – Day 25 – Working with Files and Folders in WP7
Learn Windows Phone 7 Development in 31 Days – Day 26 – Working with Creating a Local Database in WP7
Learn Windows Phone 7 Development in 31 Days – Day 27 – Working with Consuming an ODATA Service in WP7
Learn Windows Phone 7 Development in 31 Days – Day 28 – Working with Consuming a WCF Service in WP7
Learn Windows Phone 7 Development in 31 Days – Day 29 – Working with Encrypting Data for Security in WP7
Learn Windows Phone 7 Development in 31 Days – Day 30 – Installing and using WP7 Tool kit for Silverlight
Learn Windows Phone 7 Development in 31 Days – Day 31 – Deploying the application to the WP7 Market place

Thanks for reading this tutorial and providing continuous support. If you like my blog and if you are interested in getting the latest updates on new articles, kindly follow me through one of these options.

F5Debug FacebookF5debug LinkedInF5debug TwitterF5debug GooglePlusF5debug RSSFeed

Posted in Windows Phone 7 | Tagged: , , , , , , , , , , , , , , | 22 Comments »

Learn Windows Phone 7 Development in 31 Days – Day 23 – Working with Themes in WP7

Posted by Karthikeyan Anbarasan on February 23, 2012

01 Download ToolsDownload Source CodeDownload as PDF FileSubscribe to F5debugComplete Article Listing

Introduction:

In this article we are going to see how to effectively use Themes in Windows Phone 7 development. As we all know a theme is a set of resources which are used to maintain the consistent look and feel for all the controls and resources used with in the Windows Phone 7 Application. Windows Phone 7 Themes plays a major role when developing applications where colors plays an important role.

Some of the advantages of using the Themes in Windows Phone 7 development is consistency across the default controls used with in the application without adjusting some of the common properties like colors, fonts, styles etc. We can override the theme anytime at run time and in the application level with out doing much changes. Themes in Windows Phone 7 is a combination of a background and an accent color. Background color is basically the background image color which we use in our application and accent color is the one that is applied to the controls used with in the application.

Background color with Windows Phone 7 have 2 options one is Light Color and other is the dark Color and as far as Assent color considered we have 10 options which we will see in detail in our upcoming articles. Windows Phone 7 Theme are selected using the Setting options, when the user selects the theme complete application system gets changed, but again when we change some other theme only the theme related color changes with in the application scope.

Theme resources are normally maintained in the TthemeResource.XAML file, the resources are maintained based on the background color and the accent color selected by the user or the developer. Theme resources files are available on the below location based on the OS which we are using.

  • 64-bit – DriveName\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.1\Design
  • 32-bit – Drive\Program Fles\Microsoft SDKs\Windows Phone\v7.1\Design

Let us jump start to see the step by step process on how to use the themes in windows phone 7 development.

Steps:

Open Visual Studio 2010 and create a new Silverlight for Windows Phone 7 application with a valid project name as shown in the screen below.

2012-01-27 00h24_25
Now let us start with adding some colorful controls to the MainPage.XAML file and see how the UI gets affected when changing the theme. Just copy the below XAML code or drag and drop the controls from the tool box and design the UI as shown in the screen below to get the same look and feel.


XAML Code:


<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="F5DEBUG WP7 TUTORIALS" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="Themes" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>

<!--<span class="hiddenSpellError" pre="">ContentPanel</span> - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Rectangle Height="235" HorizontalAlignment="Left" Margin="38,33,0,0" Name="rectangle1"
Stroke="{StaticResource PhoneForegroundBrush}" StrokeThickness="1" VerticalAlignment="Top"
Fill= "{StaticResource PhoneAccentBrush}" Width="163" />

<Rectangle Height="235" HorizontalAlignment="Left" Margin="259,33,0,0" Name="rectangle2"
Stroke="Aqua" StrokeThickness="1" VerticalAlignment="Top" Width="163"
Fill= "Aqua"/>

<Ellipse Height="253" HorizontalAlignment="Left" Margin="38,329,0,0" Name="ellipse1"
Stroke="{StaticResource PhoneForegroundBrush}" StrokeThickness="1" VerticalAlignment="Top"
Fill= "{StaticResource PhoneAccentBrush}" Width="163" />

<Ellipse Height="253" HorizontalAlignment="Left" Margin="259,329,0,0" Name="ellipse2"
Stroke="Beige" StrokeThickness="1" VerticalAlignment="Top" Width="163"
Fill= "DarkGreen"/>
</Grid>

2012-01-27 00h54_36

In the above XAML code, if we noticed we have added 2 Rectangles and 2 Eclipses to differentiate the usage of themes in real time. The first Rectangle is designed to get the application resources details to fill the shape border color and background color, where as for the 2nd rectangle we have directly specified the color without getting the resources from the application resource. Similarly we have done the same with the Eclipse as well that the first one uses the application resource and the 2nd directly assigned with the color.

Now to tell the Windows Phone run time environment to take care of the necessary changes the theme has to do for the selection add the below code to the MainPage.XAML.cs page constructor as shown in the screen below.


Code Behind:


// Background Colour
Visibility darkBackgroundVisibility = (Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"];
//Accent Colour
Color currentAccentColorHex = (Color)Application.Current.Resources["PhoneAccentColor"];

2012-01-27 01h00_52

Now we are done with our code and we will build and execute the application by pressing F5 directly and we can see the application loads to the Windows Phone 7 Emulator as shown in the screen below.

2012-01-27 01h04_56

We can see the output shows the different colour for the first rectangle and the first eclipse since we have assigned the Application resource where themes comes into the picture. Now let us change the theme and see how the theme affects the images. Click on the Start button from the emulator and go the application listing and select setting and then themes options. Now change the Background and the Accent colour and go back to the application to check the output we can see the colour again changes for the first rectangle and the first eclipse since they are controlled with the application resource as shown in the screens below.

image

Now on changing the themes we can see the complete colour shifting as shown in the screens below which is self explanatory.

image

Conclusion:

So in this article we have seen what are themes in Windows Phone 7 development and the difference between using the theme and not using theme when application resources are used in real time.

Thanks for reading my article. If you like my blog and if you are interested in getting the latest updates on new articles, kindly follow me through one of these options.

F5Debug FacebookF5debug LinkedInF5debug TwitterF5debug GooglePlusF5debug RSSFeed

Posted in Windows Phone 7 | Tagged: , , , , , , , , , , , , , , , , , | 3 Comments »

Microsoft IT CAMPS in 4 Cities

Posted by Karthikeyan Anbarasan on February 22, 2012

Friends,

The second version of the Microsoft IT CAMPS is scheduled in 4 cities in India, Microsoft IT Camps are designed specifically for IT Infrastructure and Application Specialists, Strategic IT Managers and Tactical IT Managers – with experience of managing an organization’s IT infrastructure. The event will provide you with an opportunity to speak with and have your questions answered by Evangelists who work in infrastructure deployment and management day-in and day-out. Attend the exclusive technical sessions, armed with your questions on Private Cloud, System Centre Technologies, Infrastructure Components, and related technologies. Below is the planned agenda for this 4-city(Mumbai, Hyderabad, Bangalore and Chennai) event series.

 

AGENDA:

09:00am – 10:00am Registration

10:00am – 10:15am Welcome Keynote

10:15am – 11:00am Understanding the Microsoft Private Cloud

11:00am – 11:20am Overview of the System Center Technologies

11:20am – 11:35am Tea and Coffee break

11:35am – 12:35pm Deploy and Manage the Infrastructure Components

12:35pm – 01:35pm Lunch

01:35pm – 02:35pm Deploy and Manage the Private Cloud Infrastructure

02:35pm – 04:35pm Deploy and Manage the Service Layer

04:35pm – 04:50pm Tea and Coffee break

04:50pm – 05:50pm Deploy and Manage the Applications and VM’s

05:50pm – 06:00pm Ask the Experts [Q & A]

Venue Details and Timing:

Mumbai:

  • Date - March 2, 2012 , 9:00AM to 6:00PM
  • Venue – The Leela
  • Address Sahar, Mumbai, Maharashtra

Hyderabad:

  • Date – March 7, 2012, 9:00AM to 6:00PM
  • Venue – Taj Deccan
  • Address – Banjara Hills, Hyderabad, Andhra Pradesh

Bangalore:

  • Date – March 9, 2012, 9:00AM to 6:00PM
  • Venue – Taj Vivanta
  • Address – MG Road Bangalore, Karnataka

Chennai:

  • Date – March 13, 2012, 9:00AM to 6:00PM
  • Venue – Le Royal Meridien
  • Address – #1, GST Road, St. Thomas Mount, Chennai, Tamil Nadu

Registration Link – http://www.microsoft.com/india/events/itcamps/registration.aspx

Why to wait, register for the event in your respective city and enjoy!!!

Posted in IT CAMPS | Tagged: , , | Leave a Comment »

Learn Windows Phone 7 Development in 31 Days – Day 22 – Working with Device Information in WP7

Posted by Karthikeyan Anbarasan on February 22, 2012

01 Download ToolsDownload Source CodeDownload as PDF FileSubscribe to F5debugComplete Article Listing

Introduction:

In this article we are going to see how to get the Device information for managing the device. We will see how to make use of the Device detection API’s available with the Windows Phone 7 SDK to detect the Device information, Memory detection, Keyboard installed or not etc with the API.

To detect the device information, we are going to use the DeviceExtendedProperties class. We have different options to get the information of the device, network etc.. with the API. We will see only retrieving the device information here with this article. We are going to retrieve the below list of device information

    S No                    Information                                Description
1 DeviceUniqueId Gets device Unique ID.
2 DeviceManufacturer Gets Device Manufacture details.
3 ApplicationCurrentMemoryUsage Gets Application Memory Usage.
4 ApplicationPeakMemoryUsage Gets Application Memory Leak Usage.
5 DeviceName Gets the Device Name.
6 DeviceFirmwareVersion Gets the Firmware Version.
7 DeviceHardwareVersion Gets the Hardware Version.
8 DeviceTotalMemory Gets the physical Memory RAM Usage.
9 Power Source Indicates if the device works with power or battery.
10 Iskeyboardpresent Indicates if any physical keyboard is installed with device
11 IsKeyboardDeployed Indicates if the user deploy the physical keyboard
12 ApplicationMemoryUsageLimit Gets the maximum amount of memory.

Let us jump start to see the step by step process on how to implement the device information class to get the information and show it to the end users.

Steps:

Open Visual Studio 2010 and create a new Silverlight for Windows Phone 7 Application with a valid project name as shown in the screen below.

2012-01-26 20h25_16
Now let us start with our design to see the device informations in one page. Once we are done with the design we can see the screen looks like below screen. Just copy the XAML code to get the same look and feel. Else we can directly drag and drop the controls from the tool box and design it as per the requirement.

XAML Code:


<phone:PhoneApplicationPage
x:Class="F5debugWp7DeviceInformation.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="F5DEBUG WP7 TUTORIALS" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="Device Info" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>

<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock Height="30" HorizontalAlignment="Left" Margin="12,23,0,0" Name="ttDeviceInfo" Text="F5debug - Device Information List" VerticalAlignment="Top" Width="438" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="12,76,0,0" Name="ttdeviceuniqueid" Text="Device Unique ID:" VerticalAlignment="Top" Width="176" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="218,76,0,0" Name="txtDeviceUniqueID" Text="" VerticalAlignment="Top" Width="219" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="12,112,0,0" Name="textBlock4" Text="Device Manufacturer:" VerticalAlignment="Top" Width="200" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="218,112,0,0" Name="txtDeviceManufacturer" Text="" VerticalAlignment="Top" Width="219" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="12,148,0,0" Name="textBlock6" Text="Device Name:" VerticalAlignment="Top" Width="200" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="218,148,0,0" Name="txtDeviceName" Text="" VerticalAlignment="Top" Width="219" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="12,184,0,0" Name="textBlock8" Text="Firmware Version:" VerticalAlignment="Top" Width="200" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="218,184,0,0" Name="txtFirmwareVersion" Text="" VerticalAlignment="Top" Width="219" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="12,220,0,0" Name="textBlock10" Text="Hardware Version:" VerticalAlignment="Top" Width="200" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="218,220,0,0" Name="txtHardwareVersion" Text="" VerticalAlignment="Top" Width="219" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="12,251,0,0" Name="textBlock12" Text="Total Memory:" VerticalAlignment="Top" Width="200" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="218,251,0,0" Name="txtTotalMemory" Text="" VerticalAlignment="Top" Width="219" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="12,287,0,0" Name="textBlock14" Text="Current Memory:" VerticalAlignment="Top" Width="200" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="218,287,0,0" Name="txtCurrentMemory" Text="" VerticalAlignment="Top" Width="219" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="12,323,0,0" Name="textBlock16" Text="Peak Memory:" VerticalAlignment="Top" Width="200" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="218,323,0,0" Name="txtPeakMemory" Text="" VerticalAlignment="Top" Width="219" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="12,394,0,0" Name="textBlock18" Text="Power Source:" VerticalAlignment="Top" Width="200" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="218,394,0,0" Name="txtPowerSource" Text="" VerticalAlignment="Top" Width="219" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="12,430,0,0" Name="textBlock20" Text="Keyboard Installed:" VerticalAlignment="Top" Width="200" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="218,430,0,0" Name="txtkeyboardinstalled" Text="" VerticalAlignment="Top" Width="219" />
<Button Content="Get Details" Height="72" HorizontalAlignment="Left" Margin="46,520,0,0" Name="button1" VerticalAlignment="Top" Width="359" Click="button1_Click" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="12,467,0,0" Name="textBlock3" Text= "Keyboard Deployed:" VerticalAlignment="Top" Width="200" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="218,467,0,0" Name="txtKeyboardDeployed" Text="" VerticalAlignment="Top" Width="219" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="12,359,0,0" Name="textBlock1" Text="Maximum Memory:" VerticalAlignment="Top" Width="200" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="218,359,0,0" Name="txtMaximuMemory" Text="" VerticalAlignment="Top" Width="219" />
</Grid>
</Grid>

<!--Sample code showing usage of ApplicationBar-->
<!--<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="MenuItem 1"/>
<shell:ApplicationBarMenuItem Text="MenuItem 2"/>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>-->

</phone:PhoneApplicationPage>

2012-01-26 20h58_07
Now let us start with our code to get the device information and load it to the respective text blocks one by one as shown in the code below. We can use the Device Status class to get the details of the device properties except the device unique ID. We will write the code later to get the unique id of the device.

Code Behind:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Info;
using System.Windows.Threading;

namespace F5debugWp7DeviceInformation
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}

private void button1_Click(object sender, RoutedEventArgs e)
{
txtCurrentMemory.Text = DeviceStatus.ApplicationCurrentMemoryUsage.ToString();
txtMaximuMemory.Text = DeviceStatus.ApplicationMemoryUsageLimit.ToString();
txtPeakMemory.Text = DeviceStatus.ApplicationPeakMemoryUsage.ToString();
txtTotalMemory.Text = DeviceStatus.DeviceTotalMemory.ToString();

txtDeviceManufacturer.Text = DeviceStatus.DeviceManufacturer.ToString();
txtDeviceName.Text = DeviceStatus.DeviceName.ToString();

txtFirmwareVersion.Text = DeviceStatus.DeviceFirmwareVersion.ToString();
txtHardwareVersion.Text = DeviceStatus.DeviceHardwareVersion.ToString();

txtKeyboardDeployed.Text = DeviceStatus.IsKeyboardDeployed.ToString();
txtkeyboardinstalled.Text = DeviceStatus.IsKeyboardPresent.ToString();

txtPowerSource.Text = DeviceStatus.PowerSource.ToString();

//txtDeviceUniqueID.Text = "";
}
}
}

2012-01-26 21h18_57
Now let us write the code for getting the Device Unique ID as shown in the code below. We use the DeviceExtendedProperties property TryGetValue to get the Unique ID, since we get it as a byte array we do a conversion to the string and assign it to the text block as shown below.

Code Behind:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Info;
using System.Windows.Threading;

namespace F5debugWp7DeviceInformation
{
public partial class MainPage : PhoneApplicationPage
{
public static string val;

// Constructor
public MainPage()
{
InitializeComponent();
}

private void button1_Click(object sender, RoutedEventArgs e)
{
txtCurrentMemory.Text = DeviceStatus.ApplicationCurrentMemoryUsage.ToString();
txtMaximuMemory.Text = DeviceStatus.ApplicationMemoryUsageLimit.ToString();
txtPeakMemory.Text = DeviceStatus.ApplicationPeakMemoryUsage.ToString();
txtTotalMemory.Text = DeviceStatus.DeviceTotalMemory.ToString();

txtDeviceManufacturer.Text = DeviceStatus.DeviceManufacturer.ToString();
txtDeviceName.Text = DeviceStatus.DeviceName.ToString();

txtFirmwareVersion.Text = DeviceStatus.DeviceFirmwareVersion.ToString();
txtHardwareVersion.Text = DeviceStatus.DeviceHardwareVersion.ToString();

txtKeyboardDeployed.Text = DeviceStatus.IsKeyboardDeployed.ToString();
txtkeyboardinstalled.Text = DeviceStatus.IsKeyboardPresent.ToString();

txtPowerSource.Text = DeviceStatus.PowerSource.ToString();

string strUniID = GetDeviceUniqueID();

txtDeviceUniqueID.Text = strUniID.ToString();
}

public string GetDeviceUniqueID()
{
byte[] getresult = null;
object uniqueId;
if (DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out uniqueId))
{
getresult = (byte[])uniqueId;
}
val = Convert.ToBase64String(getresult);
return val;
}

}
}

2012-01-26 21h26_49

Now we are done with our code, let us build and execute the application by pressing F5 directly from the keyboard and we can see the application loaded to the Windows Phone 7 Emulator as shown in the screen below with the expected output.

image

Conclusion:

So in this article we have seen how to get the device information details and the device unique id using the Device Status class in detail.

Thanks for reading my article. If you like my blog and if you are interested in getting the latest updates on new articles, kindly follow me through one of these options.

F5Debug FacebookF5debug LinkedInF5debug TwitterF5debug GooglePlusF5debug RSSFeed

Posted in Windows Phone 7 | Tagged: , , , , , , , , , , , , , , , , , , , | 2 Comments »

Learn Windows Phone 7 Development in 31 Days – Day 21 – Working with BING Map Control in WP7

Posted by Karthikeyan Anbarasan on February 21, 2012

01 Download ToolsDownload Source CodeDownload as PDF FileSubscribe to F5debugComplete Article Listing

Introduction:

In this article we are going to see the most useful control on the Windows Phone 7 development, yes the BING Map Control. The BING Map Silverlight control for Windows Phone 7 development combines the power of Silverlight and Bing maps to get the best mapping experience for the developers and the real users to create location based application.

BING Map control in Windows Phone 7 application development are derived from the name spaces Microsoft.Phone.Controls and Microsoft.Phone.Controls.Maps. Developers need to register for the BING Map developers account to get the keys which are used in developing the application with the Bing Maps. Here in this article we will see the step by step process on how to make use of the BING Maps control and get the most enriching map application.

Steps:

Open Visual Studio 2010 and create a new Silverlight for Windows Phone 7 application with a valid project name as shown in the screen below.

2012-01-26 16h51_59

Note – To get the BING Map Keys first we need to register to the BING Map account using the below URL

http://www.bingmapsportal.com/

Once we register with our valid Windows Live ID we need to login again and go to the section Create or View Keys under the My Account category

2012-01-26 16h57_24

Now we will be requested to provide the application details like below

  • Application name: a valid application name
  • Application URL: a valid application URL to access
  • Application type: a valid application type to be selected from the list

Once we provided the details we will be provided with the BING Maps key as shown in the screen below.

2012-01-26 17h01_59
Now we need to go back to the Visual Studio 2010 F5debugWp7BingMapControl project and start designing the application by dragging and dropping the BING Map control from the tool box and some buttons as shown in the screen below.


XAML Code:

<phone:PhoneApplicationPage
x:Class="F5debugWp7BingMapControl.MainPage"
xmlns="<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;">http://schemas.microsoft.com/winfx/2006/xaml/presentation"</a>
xmlns:x="<a href="http://schemas.microsoft.com/winfx/2006/xaml&quot;">http://schemas.microsoft.com/winfx/2006/xaml"</a>
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="<a href="http://schemas.microsoft.com/expression/blend/2008&quot;">http://schemas.microsoft.com/expression/blend/2008"</a>
xmlns:mc="<a href="http://schemas.openxmlformats.org/markup-compatibility/2006&quot;">http://schemas.openxmlformats.org/markup-compatibility/2006"</a>
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True" xmlns:my="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps" Loaded="PhoneApplicationPage_Loaded">

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="F5DEBUG WP7 TUTORIALS" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="Bing Maps" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>

<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<my:Map Height="523" CredentialsProvider="At7uQrXAsuZLAGFyv2pz6MGQ6-EhRIqjd1l0zTto9HhHzV2VcClvIQBbumcUz74S" HorizontalAlignment="Left" Margin="6,6,0,0" Name="map1" VerticalAlignment="Top" Width="444" />
</Grid>
</Grid>

<!--Sample code showing usage of ApplicationBar-->
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/appbar.share.rest.png" Text="Road View" Click="ApplicationBarIconButton_Click"/>
<shell:ApplicationBarIconButton IconUri="/Images/appbar.feature.video.rest.png" Text="Aerial View" Click="ApplicationBarIconButton_Click_1"/>
<shell:ApplicationBarIconButton IconUri="/Images/appbar.back.rest.png" Text="Zoom In" Click="ApplicationBarIconButton_Click_2"/>
<shell:ApplicationBarIconButton IconUri="/Images/appbar.next.rest.png" Text="Zoom Out" Click="ApplicationBarIconButton_Click_3"/>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

</phone:PhoneApplicationPage>

2012-01-26 17h21_05
Now we need to use the below using directive to start using the map properties to the code behind. So add the below code first to the using list at the top

Code Behind:

using Microsoft.Phone.Controls.Maps;

Now we need to add below code to the Road View and Aerial View button click events as shown in the code below.


Code Behind:


private void ApplicationBarIconButton_Click(object sender, EventArgs e)
{
map1.Mode = new RoadMode();
}

private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
{
map1.Mode = new AerialMode();
}

2012-01-26 17h27_56
Now build and execute the application to check the first 2 button is working as expected. Press F5 to start building the project and we can see the application loaded to the Windows Phone 7 Emulator as shown in the screen below.

2012-01-26 17h35_03

We can see a message Invalid Credentials: Sign up for a developer account at: http://www.microsoft.com/maps/developers as shown in the screen above. To remove this message we need to make use of the key which we got after registering with the Bing Maps website. So go to the XAML Code and add the key to the BING Maps section as shown in the screen below.


XAML Code:


<my:Map Height="523" CredentialsProvider="Insert the KEY here" HorizontalAlignment="Left" Margin="6,6,0,0" Name="map1" VerticalAlignment="Top" Width="444" />

2012-01-26 17h40_53

Now run the application again by pressing the F5 key and we can see the error message is removed and the application in Aerial View and Road View as shown in the screens below.

2012-01-26 17h57_03
Now we will write our code to do the zooming for the maps. Write the below code in the respective code behind to get the Zoom in and Zoom out as shown in the code below.


Code Behind:


private void ApplicationBarIconButton_Click_2(object sender, EventArgs e)
{
double dbZoom;
dbZoom = map1.ZoomLevel;
map1.ZoomLevel = ++dbZoom;
}

private void ApplicationBarIconButton_Click_3(object sender, EventArgs e)
{
double dbZoom;
dbZoom = map1.ZoomLevel;
map1.ZoomLevel = --dbZoom;
}

2012-01-26 18h03_34
Now build and execute the project and we can see the Zoom in and Zoom out of the maps effectively as shown in the screens below.

image
Now we got the expected output as shown in the above screens, now let us do a add on task of pinning the location normally we need to do while travelling using a map direction. To start coding the PINNING option first add the map1_MouseLeftButtonUp event and write the below code which will do the location pinning as shown in the screen below.

Code Behind:


int intcount = 0;
private void map1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
intcount = intcount + 1;
Pushpin pn = new Pushpin();
pn.Location = map1.ViewportPointToLocation(e.GetPosition(sender as Map));
pn.Content = "Location" + intcount;

(sender as Map).Children.Add(pn);
}

2012-01-26 19h17_55

Now we are done with our code, let us build and execute the application by pressing F5 and we can see the expected output. Just use the Mouse Up to click on the location shown in the Windows Phone 7 Emulator to pin the location as shown in the screens below.

image

Conclusion:

So in this article we have seen how to use the BING Map control effectively with the Windows Phone 7 development to build a rich user experience.

Thanks for reading my article. If you like my blog and if you are interested in getting the latest updates on new articles, kindly follow me through one of these options.

F5Debug FacebookF5debug LinkedInF5debug TwitterF5debug GooglePlusF5debug RSSFeed

Posted in Windows Phone 7 | Tagged: , , , , , , , , , , , , , , , , | 1 Comment »