Sunday, November 6, 2011

Windows Phone 7 - Initial Days


In this series of blogs we will look at Windows Phone 7 (WP7) development platform and a discussion on what is best for your application along with a few simple examples followed by advanced concepts in subsequent posts. In a nutshell there are two choices when it comes to platforms: Silverlight and XNA. The former is more apt for utility applications and the later for absolute gaming. What suites your business requirement, device and users is a choice you can make between these two. As an example, let’s take a scenario where an on/off-screen key board is a must and you have a perfect case to use Silverlight as against XNA which is apt for gaming sort of application.
As far as development is concerned, i am of the opinion to leverage both C# and Blend thereby minimizing the development and testing time. A popular notion is that to use Blend for design phase and Visual Studio to develop the application. In my honest opinion a lot more can be leveraged by delegating C# code aspects to Blend. There is an emulator available which lets you develop and test without having to connect to an actual device. Let’s jump into a quick example and explore further. We will look at orientation and image related features. Since I am using an emulator, let’s defer multi touch concepts to subsequent posts. After installing (VS2010 Express Edition & Expression Blend 4) for Windows Phone, create a new Silverlight for Windows Phone application and from the MainPage.XAML set the following: - SupportedOrientations="PortraitOrLandscape". More on basics of XAML can be found from earlier blog posts. Since Silverlight supports only JPEG and PNG image files, let’s quickly add a folder to the Project in Solution Explorer and from the folder, add an existing item in the form of a PNG file that already exists on your computer. Make sure to set the source in the XAML file from the content grid tag by typing Image Source="folder_name/Image_name.PNG"(in angular brackets). Hit F5 and you should see the following before and after rotating the emulator:
Now let’s add a picture from the web as the size of the Project may be of a concern if there are multiple images. Launch Blend and add a few buttons. Click on the events icon for each button and name the methods as btn_1 and btn_2 respectively which are created against the event handler ‘ManipulationStarted’. This step creates all the necessary code for the event handling part and this is where I strongly feel that one should leverage Blend as stated earlier to create the error free code for you. More on how can also be found from earlier blogs on Blend.
Add the following C# code to the methods created above:
Uri uri = new Uri("http://www.YOUR_URL/xyz.jpg");
BitmapImage bmp = new BitmapImage(uri);
img.Source = bmp; // Where img is the directory created earlier in Solution Explorer.
Hit F5 and upon clicking the buttons (touching on real phone), the images are rendered from the web. I would conclude by recommending a good read of the Preview content offered by Microsoft from where I have taken some inputs. Commercial releases of the content might be available by now!

No comments:

Post a Comment