Visual Basic Windows Phone 7 Series #7. How to create a Bing Maps application for Windows Phone 7

Posted in Visual Basic on March 31st, 2011 by Admin

In our previous post, I explained how to create an application bar for Windows Phone 7. Bing Maps is one of the applications that is commonly used on phones these days. In this blog post, I want to share a sample that will help you to create a Bing Maps application for Windows Phone 7. This application will provide the feature to view maps in road view and aerial view. This application will also provide the zooming in and zooming out features.

I will now demonstrate how easy it is to create a Bing Maps application for Windows Phone 7, using Visual Basic for Windows Phone Developer Tools. The Bing Maps application can be created in 4 simple steps as follows:

  1. Create a sample application and add controls
  2. Add event handlers
  3. Build and debug the application
  4. Rebuild in the release mode before publishing

Prerequisites:

To create the Bing maps application, let’s follow the 4 simple steps mentioned earlier:

Step 1 – Create a sample application and add controls

Create a sample application

  1. Create a new project and browse to the “Silverlight for Windows Phone” node.
  2. Select the “Windows Phone Application” template.
  3. Enter a name for the application.
  4. Click OK. The MainPage.xaml page is displayed.

Add controls

  1. Click the MY APPLICATION text. In the Properties window, change the Text property to “Bing Maps Silverlight Control Sample”.
  2. Click the page name text. In the Properties window, change the Text property to “Bing Maps”.
  3. From the toolbox, drag and drop the Map control to the design surface.
  4. From the toolbox, drag and drop the Button control to the design surface.
  5. Click the Button control. In the Properties window, change the Content property to “Road Mode”.
  6. From the toolbox, drag and drop a new Button control to the design surface.
  7. Click the Button control. In the Properties window, change the Content property to “Aerial Mode”.
  8. From the toolbox, drag and drop a new the Button control to the design surface.
  9. Click the Button control. In the Properties window, change the Content property to “Zoom In”.
  10. From the toolbox, drag and drop a new Button control to the design surface.
  11. Click the Button control. In the Properties window, change the Content property to “Zoom Out”.
  12. Add the following XAML code to set the height, width, and the alignment of the Map and the Button controls:

    <Grid x:Name=”ContentPanel” Grid.Row=”1″ Margin=”12,0,12,0″>

       <my:Map Height=”462″ HorizontalAlignment=”Left” Margin=”6,6,0,0″ Name=”map1″ VerticalAlignment=”Top” Width=”444″ />

       <Button Content=”Zoom In” Height=”72″ HorizontalAlignment=”Left” Margin=”6,535,0,0″ Name=”buttonZoomIn” VerticalAlignment=”Top” Width=”207″ />

       <Button Content=”Road Mode” Height=”72″ HorizontalAlignment=”Left” Margin=”6,474,0,0″ Name=”buttonRoad” VerticalAlignment=”Top” Width=”207″ />

       <Button Content=”Zoom Out” Height=”72″ HorizontalAlignment=”Left” Margin=”243,535,0,0″ Name=”buttonZoomOut” VerticalAlignment=”Top” Width=”207″ />

       <Button Content=”Aerial Mode” Height=”72″ HorizontalAlignment=”Left” Margin=”243,474,0,0″ Name=”buttonAerial” VerticalAlignment=”Top” Width=”207″ />

    </Grid>

Your application now looks like this:

Step 2 – Add event handlers

Adding event handlers is one of the important tasks. These event handlers are required to switch the map modes from aerial view to road view and vice versa when the appropriate button is clicked.

To add the event handlers:

  1. Double-click the Road Mode button. The MainPage.xaml.vb page is displayed.
  2. Replace the buttonRoad_Click event handler with the following code:

    Private Sub buttonRoad_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)

         map1.Mode = New RoadMode()

    End Sub

  3. Open the MainPage.xaml page. Double-click the Aerial Mode button. The MainPage.xaml.vb page is displayed.
  4. Replace the buttonAerial_Click event handler with the following code:

    Private Sub buttonAerial_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)

         map1.Mode = New AerialMode()

    End Sub

  5. Open the MainPage.xaml page. Double-click the Zoom In button. The MainPage.xaml.vb page is displayed.
  6. Replace the buttonZoomIn_Click event handler with the following code:

    Private Sub buttonZoomIn_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)

         Dim zoom = map1.ZoomLevel

         zoom += 1

         map1.ZoomLevel = zoom

    End Sub

  7. Open the MainPage.xaml page. Double-click the Zoom Out button. The MainPage.xaml.vb page is displayed.
  8. Replace the buttonZoomOut_Click event handler with the following code:

    Private Sub buttonZoomOut_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)

         Dim zoom = map1.ZoomLevel

         zoom -= 1

         map1.ZoomLevel = zoom

    End Sub

Now your Bing Maps application for Windows Phone 7 is ready! You just need to build and debug the application.

Step 3 – Build and debug the application

  1. To build the application, select Build > Build Solution. The project should build without any errors.
  2. To debug the application, set the deployment target of the application to “Windows Phone 7 Emulator”.
  3. Select Debug > Start Debugging. The emulator window is displayed.
  4. To test the aerial view, click the Aerial Mode button.
  5. To zoom in the map, click the Zoom In button.
  6. To zoom out and return to the initial map size, click the Zoom Out button.

Note: To stop debugging the application, select Debug > Stop Debugging.

Your Bing Maps application for Windows Phone 7 is ready to be published into the marketplace. Now, you just need to rebuild your application for the release.

Step 4 – Rebuild in the release mode before publishing

  1. On the standard toolbar, change the configuration manager to Release.
  2. To rebuild the application, select Build > Rebuild. The XAP file of the application is generated, which is the package that you will have to submit in the marketplace to publish the application. You can also locate this XAP file in the Bin\Release folder.

Finally, to submit your application to the market place, you can refer to upload your application walkthrough.

Summary

That’s it! We’ve now seen that creating a Bing Maps application 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 application here.


The Visual Basic Team

Tags: , , , , , , , ,

Cocoa Framework a mirror image of Actionscript ?

Posted in IPhone App Programming on March 31st, 2011 by Admin

Flash and Cocoa are shockingly similar. Much of the Cocoa framework is a mirror image of Actionscript classes / components. For example:

  • UIView = MovieClip
  • NSNotification = Event
  • UIButton = Button

Read the full article here

[source Insideria]

iPhoneDevelopmentBits

Tags: , , , ,

Android Widgets

Posted in Video Game Programming on March 30th, 2011 by Admin

I’ve spent the last few days (actually started over the Christmas break) to create a widget for my android app. It is easy to get it started but I want mine to update every second or so; depending on user configuration. My last effort resulted in a binding error while I tried to push a bitmap down to widget. !!!FAILED BINDER TRANSACTION!!! I’m still looking for a solution so if you know of one; please leave a comment!

Here is my latest reading list!:
* http://developer.android.com/guide/topics/intents/intents-filters.html
* http://stackoverflow.com/questions/2181588/whats-the-proper-way-to-implement-an-android-widget-with-dynamically-drawn-conte

* http://android-developers.blogspot.com/2009/04/introducing-home-screen-widgets-and.html


Programming: Robots & Video Games

Tags: ,

Graphic Adventure Games

Posted in Video Game Programming on March 30th, 2011 by Admin

What would I love to be doing now instead of making video games about petting animals?

I’d love to make a cool story driven adventure game.  I’ve finished Heavy Rain a few weeks ago and loved it although there is still so much room for improvement.  I love Monkey Island.  I love Resident Evil series because they were basically adventures with a bit of shooting.  With that in mind I love Uncharted.  I really like Bioshock but too much RPG does put me off since I like to be in and out of a story.  I’d love to play Fallout3 and Oblivion but I couldn’t invest the time.

A history of graphic adventure games

I got Little Big Planet 2 for my son (and myself) the other day and it is really good for creating new games on.  I should sit with him and create an adventure.   That should be easy enough!  (Famous last words!)


Programming: Robots & Video Games

Tags: , ,

Visual Basic Windows Phone 7 Series #8. How to create a settings page for Windows Phone 7

Posted in Visual Basic on March 29th, 2011 by Admin

I have experienced lot of fun creating Windows Phone 7 applications in Visual Basic and writing about them here. In our last post, I explained how to create a Bing Maps application for Windows Phone 7. In this blog, I want to share a sample that will help you to create a settings page for Windows Phone 7. This application will display two setting pages – one where the setting changes will be updated immediately, and the other where the user will have to confirm the changes.

I will now demonstrate how easy it is to create a settings page for Windows Phone 7, using Visual Basic for Windows Phone Developer Tools. The settings page can be created in 6 simple steps as follows:

  1. Create a sample application and add controls
  2. Create a settings class
  3. Create a settings page that does not require a confirmation button
  4. Create a settings page that requires a confirmation button
  5. Build and debug the application
  6. Rebuild in the release mode before publishing

Prerequisites:

To create a settings page for Windows Phone 7, let’s follow the 6 simple steps mentioned earlier:

Step 1 – Create a sample application and add controls

Create a sample application

  1. Create a new project and browse to the “Silverlight for Windows Phone” node.
  2. Select the “Windows Phone Application” template.
  3. Enter a name for the application.
  4. Click Ok. The MainPage.xaml page is displayed.

Add controls

  1. Click the MY APPLICATION text. In the Properties window, change the text property to “Windows Phone 7 Sample”.
  2. Click the page name text. In the Properties window, change the text property to “Settings Sample”.
  3. From the toolbox, drag and drop the TextBlock control to the design surface.
  4. Click the TextBlock control. In the Properties window, change the text property to “This sample shows two Settings screens, one where the settings changes take effect immediately and one where the user has to confirm the changes. The settings are stored in Isolated Storage. You can navigate to the Settings screens using the menu item on the Application Bar below.”.
  5. Open the MainPage.xaml.vb page. The page is displayed with the following code:

    Partial Public Class MainPage

        Inherits PhoneApplicationPage

     

        ‘ Constructor

        Public Sub New()

            InitializeComponent()

        End Sub

    End Class

  6. Replace the code in Step 5 with the following code:

    Partial Public Class MainPage

        Inherits PhoneApplicationPage

     

        ‘ Constructor

        Public Sub New()

            InitializeComponent()

     

            SupportedOrientations = SupportedPageOrientation.Portrait

     

            ‘ Add an Application Bar with a ‘setting menu item.

            ApplicationBar = New ApplicationBar()

            ApplicationBar.IsMenuEnabled = True

            ApplicationBar.IsVisible = True

            ApplicationBar.Opacity = 1.0

     

            Dim settingsItem As New ApplicationBarMenuItem(“settings”)

            AddHandler settingsItem.Click, AddressOf settings_Click

     

            ApplicationBar.MenuItems.Add(settingsItem)

     

        End Sub

     

     

        Private Sub settings_Click(ByVal sender As Object, ByVal e As EventArgs)

            Me.NavigationService.Navigate(New Uri(“/SettingsWithoutConfirmation.xaml”, UriKind.Relative))

        End Sub

     

    End Class

    Note: This method creates an application bar containing a settings menu item. This menu item is required by the user to navigate to the settings page that does not require the confirmation button.

Step 2 – Create a settings class

Creating a settings class is one of the important tasks. This class is required to hold, save, and then load the settings from isolated storage. This class will contain a method to add or update a value to isolated storage. This method will also assign a default value if the setting has never been set earlier.

  1. In Solution Explorer, right-click the application name and add a class. The Add New Item dialog box is displayed.
  2. Enter the name as “AppSettings.vb”, and then click Add. The AppSettings.vb page is displayed.
  3. Replace the code with the following code:

    Imports System.IO.IsolatedStorage

    Imports System.Diagnostics

     

    Public Class AppSettings

        ‘ Our isolated storage settings

        Private isolatedStore As IsolatedStorageSettings

        ‘ The isolated storage key names of our settings

        Private Const CheckBoxSettingKeyName As String = “CheckBoxSetting”

        Private Const ListBoxSettingKeyName As String = “ListBoxSetting”

        Private Const RadioButton1SettingKeyName As String = “RadioButton1Setting”

        Private Const RadioButton2SettingKeyName As String = “RadioButton2Setting”

        Private Const RadioButton3SettingKeyName As String = “RadioButton3Setting”

        Private Const UsernameSettingKeyName As String = “UsernameSetting”

        Private Const PasswordSettingKeyName As String = “PasswordSetting”

        ‘ The default value of our settings

        Private Const CheckBoxSettingDefault As Boolean = True

        Private Const ListBoxSettingDefault As Integer = 0

        Private Const RadioButton1SettingDefault As Boolean = True

        Private Const RadioButton2SettingDefault As Boolean = False

        Private Const RadioButton3SettingDefault As Boolean = False

        Private Const UsernameSettingDefault As String = “”

        Private Const PasswordSettingDefault As String = “”

     

        ”’ Constructor that gets the application settings.

        Public Sub New()

            Try

                ‘ Get the settings for this application.

                isolatedStore = IsolatedStorageSettings.ApplicationSettings

            Catch e As Exception

                Debug.WriteLine(“Exception while using IsolatedStorageSettings: “ & e.ToString())

            End Try

        End Sub

       

        ”’ Update a setting value for our application. If the setting does not

        ”’ exist, then add the setting.

        Public Function AddOrUpdateValue(ByVal Key As String, ByVal value As Object) As Boolean

            Dim valueChanged As Boolean = False

            Try

                ‘ if new value is different, set the new value.

                If isolatedStore(Key) IsNot value Then

                    isolatedStore(Key) = value

                    valueChanged = True

                End If

            Catch e1 As KeyNotFoundException

                isolatedStore.Add(Key, value)

                valueChanged = True

            Catch e2 As ArgumentException

                isolatedStore.Add(Key, value)

                valueChanged = True

            Catch e As Exception

                Debug.WriteLine(“Exception while using IsolatedStorageSettings: “ & e.ToString())

            End Try

            Return valueChanged

        End Function

     

       

        ”’ Get the current value of the setting, or if it is not found, set the

        ”’ setting to the default setting.

        Public Function GetValueOrDefault(Of valueType)(ByVal Key As String, ByVal defaultValue As valueType) As valueType

            Dim value As valueType

            Try

                value = CType(isolatedStore(Key), valueType)

            Catch e1 As KeyNotFoundException

                value = defaultValue

            Catch e2 As ArgumentException

                value = defaultValue

            End Try

            Return value

        End Function

        

        ”’ Save the settings.

        Public Sub Save()

            isolatedStore.Save()

        End Sub

     

        ”’ Property to get and set a CheckBox Setting Key.

        Public Property CheckBoxSetting() As Boolean

            Get

                Return GetValueOrDefault(Of Boolean)(CheckBoxSettingKeyName, CheckBoxSettingDefault)

            End Get

            Set(ByVal value As Boolean)

                AddOrUpdateValue(CheckBoxSettingKeyName, value)

                Save()

            End Set

        End Property

     

        ”’ Property to get and set a ListBox Setting Key.

        Public Property ListBoxSetting() As Integer

            Get

                Return GetValueOrDefault(Of Integer)(ListBoxSettingKeyName, ListBoxSettingDefault)

            End Get

            Set(ByVal value As Integer)

                AddOrUpdateValue(ListBoxSettingKeyName, value)

                Save()

            End Set

        End Property

     

        ”’ Property to get and set a RadioButton Setting Key.

        Public Property RadioButton1Setting() As Boolean

            Get

                Return GetValueOrDefault(Of Boolean)(RadioButton1SettingKeyName, RadioButton1SettingDefault)

            End Get

            Set(ByVal value As Boolean)

                AddOrUpdateValue(RadioButton1SettingKeyName, value)

                Save()

            End Set

        End Property

     

       

        ”’ Property to get and set a RadioButton Setting Key.

        Public Property RadioButton2Setting() As Boolean

            Get

                Return GetValueOrDefault(Of Boolean)(RadioButton2SettingKeyName, RadioButton2SettingDefault)

            End Get

            Set(ByVal value As Boolean)

                AddOrUpdateValue(RadioButton2SettingKeyName, value)

                Save()

            End Set

        End Property

     

        ”’ Property to get and set a RadioButton Setting Key.

        Public Property RadioButton3Setting() As Boolean

            Get

                Return GetValueOrDefault(Of Boolean)(RadioButton3SettingKeyName, RadioButton3SettingDefault)

            End Get

            Set(ByVal value As Boolean)

                AddOrUpdateValue(RadioButton3SettingKeyName, value)

                Save()

            End Set

        End Property

     ”’ Property to get and set a Username Setting Key.

        Public Property UsernameSetting() As String

            Get

                Return GetValueOrDefault(Of String)(UsernameSettingKeyName, UsernameSettingDefault)

            End Get

            Set(ByVal value As String)

                AddOrUpdateValue(UsernameSettingKeyName, value)

                Save()

            End Set

        End Property

     

        ”’ Property to get and set a Password Setting Key.

        Public Property PasswordSetting() As String

            Get

                Return GetValueOrDefault(Of String)(PasswordSettingKeyName, PasswordSettingDefault)

            End Get

            Set(ByVal value As String)

                AddOrUpdateValue(PasswordSettingKeyName, value)

                Save()

            End Set

        End Property

    End Class

     

Step 3 – Create a settings page that does not require a confirmation button

  1. In Solution Explorer, right-click the application name, and then add a new item. The Add New Item dialog box is displayed.
  2. Select the “Silverlight for Windows Phone” node, and then select the “Windows Phone User Control” template.
  3. Enter the name as “SettingsWithoutConfirmation.xaml”, and then click Add. The SettingsWithoutConfirmation.xaml page is displayed.
  4. Add the following XAML code in the namespace declaration:

    xmlns:phone=”clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone”

    xmlns:shell=”clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone”

       

    xmlns:local=”clr-namespace:SettingsSample”

  5. To add a local resource, add the following XAML code before the <Grid> tag:

    <phone:PhoneApplicationPage.Resources>

            <local:AppSettings x:Key=”appSettings”></local:AppSettings>

    </phone:PhoneApplicationPage.Resources>

  6. To create buttons, add the following XAML code in the <Grid> tag:

    <CheckBox Content=”CheckBox Setting” Height=”Auto” HorizontalAlignment=”Left” Margin=”60,20,0,0″ Name=”checkBoxSetting” VerticalAlignment=”Top” IsChecked=”{Binding Source={StaticResource appSettings}, Path=CheckBoxSetting, Mode=TwoWay}”  />

     

    <ListBox Height=”140″ HorizontalAlignment=”Left” Margin=”70,150,0,0″ Name=”listBoxSetting” VerticalAlignment=”Top” Width=”360″  SelectedIndex=”{Binding Source={StaticResource appSettings}, Path=ListBoxSetting, Mode=TwoWay}”>

          

           <ListBoxItem Content=”Times New Roman” FontSize=”24″ FontFamily=”Times New Roman” />

           <ListBoxItem Content=”Arial” FontSize=”24″ FontFamily=”Arial” />

           <ListBoxItem Content=”Comic Sans MS” FontSize=”24″ FontFamily=”Comic Sans MS” />

    </ListBox>

     

    <RadioButton Content=”Choice One” Height=”Auto” HorizontalAlignment=”Left” Margin=”60,0,0,235″ Name=”radioButton1″ VerticalAlignment=”Bottom” GroupName=”GroupOne” IsChecked=”{Binding Source={StaticResource appSettings}, Path=RadioButton1Setting, Mode=TwoWay}” />

    <RadioButton Content=”Choice Two” Height=”Auto” HorizontalAlignment=”Left” Margin=”60,350,0,0″ Name=”radioButton2″ VerticalAlignment=”Top” GroupName=”GroupOne” IsChecked=”{Binding Source={StaticResource appSettings}, Path=RadioButton2Setting, Mode=TwoWay}”/>

    <RadioButton Content=”Choice Three” Height=”Auto” HorizontalAlignment=”Left” Margin=”60,400,0,0″ Name=”radioButton3″ VerticalAlignment=”Top” GroupName=”GroupOne” IsChecked=”{Binding Source={StaticResource appSettings}, Path=RadioButton3Setting, Mode=TwoWay}”/>

     

    <Button Content=”Settings With Confirmation” Height=”80″ HorizontalAlignment=”Left” Margin=”60,450,0,0″ Name=”buttonAdditional” Click=”buttonAdditional_Click” />

    Note: This page uses data binding for the settings to be updated immediately and then saves the values to isolated storage. Selecting the binding mode as “TwoWay” updates the changes immediately.

Step 4 – Create a settings page that requires a confirmation button

  1. In Solution Explorer, right-click the application name, and then add a new item. The Add New Item dialog box is displayed.
  2. Select the “Silverlight for Windows Phone” node, and then select the “Windows Phone User Control” template.
  3. Enter the name as “SettingsWithConfirmation.xaml”, and then click Add. The SettingsWithConfirmation.xaml page is displayed.
  4. Add the following XAML code in the namespace declaration:

    xmlns:phone=”clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone”

    xmlns:shell=”clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone” 

  5. To create buttons, add the following XAML code in the <Grid> tag:

    <TextBlock Height=”60″ HorizontalAlignment=”Left” Margin=”65,12,0,0″ Name=”textBlock1″ Text=”Username” VerticalAlignment=”Top” Width=”169″ />

    <TextBox Height=”78″ HorizontalAlignment=”Left” Margin=”60,60,0,0″ Name=”textBoxUsername”  VerticalAlignment=”Top” Width=”274″  />

    <TextBlock Height=”60″ HorizontalAlignment=”Left” Margin=”65,160,0,0″ Name=”textBlock2″ Text=”Password” VerticalAlignment=”Top” Width=”169″ />

    <PasswordBox Height=”78″ HorizontalAlignment=”Left” Margin=”60,208,0,0″ Name=”passwordBoxPassword” VerticalAlignment=”Top” Width=”274″ />

  6. Open the SettingsWithConfirmation.xaml.vb page. The page is displayed with the following code:

    Partial Public Class SettingsWithConfirmation

        Inherits PhoneApplicationPage

     

        Public Sub New()

            InitializeComponent()

        End Sub

    End Class

  7. Replace the code in Step 6 with the following code:

    Partial Public Class SettingsWithConfirmation

        Inherits PhoneApplicationPage

     

        Private settings As New AppSettings()

     

        Public Sub New()

     

            InitializeComponent()

     

            ‘ Add an Application Bar that has a ‘done’ confirmation button and

            ‘ a ‘cancel’ button

            ApplicationBar = New ApplicationBar()

            ApplicationBar.IsMenuEnabled = True

            ApplicationBar.IsVisible = True

            ApplicationBar.Opacity = 1.0

     

            Dim doneButton As New ApplicationBarIconButton(New Uri(“/Images/appbar.check.rest.png”, UriKind.Relative))

            doneButton.Text = “done”

            AddHandler doneButton.Click, AddressOf doneButton_Click

     

            Dim cancelButton As New ApplicationBarIconButton(New Uri(“/Images/appbar.cancel.rest.png”, UriKind.Relative))

            cancelButton.Text = “cancel”

            AddHandler cancelButton.Click, AddressOf cancelButton_Click

     

            ApplicationBar.Buttons.Add(doneButton)

            ApplicationBar.Buttons.Add(cancelButton)

     

            ‘ Copy the current settings into the text boxes as the new values

            ‘ entered in will not be saved until the user clicks the ‘done’ button.

            textBoxUsername.Text = settings.UsernameSetting

            passwordBoxPassword.Password = settings.PasswordSetting

     

        End Sub

     

        Private Sub doneButton_Click(ByVal sender As Object, ByVal e As EventArgs)

            settings.UsernameSetting = textBoxUsername.Text

            settings.PasswordSetting = passwordBoxPassword.Password

            NavigationService.GoBack()

        End Sub

     

        Private Sub cancelButton_Click(ByVal sender As Object, ByVal e As EventArgs)

            NavigationService.GoBack()

        End Sub

     

    End Class

    Note: This method creates an application bar with the done and the cancel buttons. These buttons are required by the user to confirm or cancel the changes. This method also creates event handlers for the button click events.

There you are! Now your settings page application for Windows Phone 7 is ready! You just need to build and debug the application.

Step 5 – Build and debug the application

  1. To build the application, select Build > Build Solution. The project should build without any errors. If there are errors, check the earlier steps, correct the errors, and then build the application again.
  2. To debug the application, set the deployment target of the application to “Windows Phone 7 Emulator”.
  3. Select Debug > Start Debugging. The emulator window is displayed.
  4. To test the settings page that does not require a confirmation button, click “settings” on the application bar. The settings screen is displayed without the confirmation button.
  5. To test the screen, click any of the options. The settings will be changed immediately and saved to isolated storage.
  6. To test the settings page that requires a confirmation button, click “Settings With Confirmation”. The settings screen is displayed with the confirmation button.
  7. Enter the username and the password details and click the Right arrow icon to confirm the changes. The settings will be changed and stored in isolated storage.

Note: To stop debugging the application, select Debug > Stop Debugging.

Step 6 – Rebuild in the release mode before publishing

  1. On the standard toolbar, change the configuration manager to Release.
  2. To rebuild the application, select Build > Rebuild. The XAP file of the application is generated, which is the package that you will have to submit in the marketplace to publish the application. You can also locate this XAP file in the Bin\Release folder.

Finally, to submit your application to the market place, you can refer to upload your application walkthrough.

Summary

Bravo! Buenos! You have successfully created a settings page for Windows Phone 7, that too in just 6 simple steps! You can find the full source code for the settings page application here. This application uses general Silverlight and Visual Basic features that are applicable for different application types including Windows Phone application.


The Visual Basic Team

Tags: , , , , , , ,

20 FREE Online CSS Resources to Quickly Enhance Your Website Design Abilities

Posted in Programming Tips on March 29th, 2011 by Admin

One of the biggest obstacles that webmasters face in their quest to creating a website is that of CSS design. Indeed, Cascading Style Sheets can be pretty frustrating to work with. Luckily for us, there are lots of online resources that provide already created and thoroughly tested code that does anything we could ask for. In this post i will be presenting you to various such resources that will hopefully help you a lot. I know that they have in my case :)

1. Listamatic – Ready Made Horizontal and Vertical CSS Lists

Would you like to create horizontal or vertical css lists and navigation menus for your website ? Search nowhere else. Listamatic is a great resource contains great examples of very stylized lists. The css is fully presented for each example and you can freely use it.

2. CSS Round Corners : Boxes With Curves

Ever wanted to create a box that is not rectangular in shape ? CSS can help you do that and this resource makes it a breeze for you. Round corners for boxes are quite a bit stylish and tend to be used a lot nowadays, so it really pays to visit this if you want to reproduce something like that.

3. CSS Layouts on Max Design

I can guarantee that you will absolutely love this. Want to create a liquid design ? Maybe want to have a 3 columned design ? Or even a middle sized right column ? This is a great and very important resource !

4. CSS Borders

Making a CSS border is something that you will most probably face when creating a website. w3schools provides you with the important information to create simple borders for your website needs.

5. CSS Image Gallery

An absolutely great and very easy to implement image gallery solely created in CSS. Great one to use if you would like to include photos as a gallery in your webpages.

6. CSS Image Maps

Have you seen those images that when you hover over an element you get some extra focus to it and maybe some information about it ? It could be a map of a United States that when you hover over a state, you get a popup describing you more about that state. These are called Image Maps and they are quiet easy to create, at least if you follow this tutorial.

7. CSS Bar Graphs

Want to create your own bar graphics ? Maybe wanting to present some percentage poll information or such? If so, this is the resource for you !

8. CSS Calendar With Notes Taking

Use this code to create your own calendar. You can also use the calendar to present some information about a certain day, like dates, things to do and such.

9. Create A “Print This Page” Version

Do you have posts that you want to create a “print this page” version too ? Luckily, this is pretty trivial using CSS and you can find all the information you need at this resource.

10. CSS Ratings Selector

Adding a rating system is very useful for very many webmasters. This Star Matrix is very easy to implement and looks pretty nice too. I’ve also happened to have used it many times in the past and it really is very stable and good looking.

11. Float Images Around Text

This is a very basic CSS technique that you can see at use at this page here. Notice that the image of this post floats at the left of the text you read at the beginning. If you want to learn more about this technique and be able to float whatever you want left or right, you should really take a look at this awesome website.

12. CSS Images With Captions

Want to create images that feature captions below them too ? It’s very easy to do as you can see !

13. LightBox Effect Using CSS Only

Have you seen those images that when you click on the whole browser gets gray and the image is presented to you closer to the screen, like popping out of the page ? This is called lightbox effect and is mostly creating using javascript techniques but this webpage explains how to do it properly using CSS only.

14. CSS Modern Forms

Smashingmagazine.com presents you to these great modern css forms to use. Most of them look really nice and are also very easy to implement.

15. Stylized CSS Blockquotes and Pullquotes

A really great and artistic way to create blockquotes and pullquotes to quote something or draw the visitor attention towards some text.

16. Advanced CSS Menu

If you are interested in creating a very fine and very eye pleasing CSS menu, you may want to take a closer look at this tutorial. You will find the full source code to creating a great CSS menu as the one described but you will need to read this through to do it. I can assure you, though, that it is really worth it.

17. Sticky CSS Footer

A simple but effective CSS footer that you can easily change to reflect your ideas. You can find the source code there and change it to whatever you feel is appropriate for you.

18. Style Tables Using CSS

Do you want to add some style to your HTML tables ? Well, i guess you do :)

19. Hyperlink Cues with CSS

These are the little icons that are shown right before a link. For instance, a link to an email address could appear a mail envelope icon. Very nice technique to use in order to add small chunks of style to your website.

20. CSS Drop Down Menus

Sometimes a drop down menu is a very nice addition to a website. This resource is incredible for such a creation. You will certainly find it very useful and it is very eye pleasurable too. Hope that you go about using those techniques in your own websites. I have used many of them at times and found them very useful and earned me lots of time. Wish the same for you too !


Programming Tips For Versatile Coders

Tags: , , , , , , ,

10 Ruby on Rails 3 Tips That Will Make You a Better Rails Programmer

Posted in Programming Tips on March 28th, 2011 by Admin

If you already are a Rails programmer, i’m pretty sure that you have already been dazzled by the things that Rails can do for you. However, all this convenience comes at a cost. That cost comes for the fact that you need to know how to work with the internal Rails conventions and traps. Since i’ve been programming in Rails for quite some months now, i would like to give you what i think are some very useful tips that will make your Rails life easier. On my previous post, i’ve described how Rails associations work, so you might want to take a look. Let’s now take a look at some important Rails techniques-tips.

1. A Relation is Different Than an Array of Records in Active Record

Take a look at the screenshot please (click on it for larger view) :

Notice that when we execute User.where(“name = ?”, ‘hthought’) and then get the class of object, we see that this one is a Relation. A Relation behaves like a pointer. It never actually executes the database query, unless asked by a specific operand. However, we can use it to get a pointer to a scope inside the database. This means that in this case :


the_users = User.where("name = ?", 'hthought')

The variable the_users is now a relation that describes a scope. This scope concerns all these users table rows that have the name ‘hthought’. Remember, at that point, no database select has been made. The actual database query will happen if we now execute :


the_users.first

This is exactly the same as the second User.where above. This one is actually an array of records now, or actual a single object, since we called first to retrieve the first record.

2. Use Ready Made Rails Plugins

We both know that we are using Rails in order to make our lives easier. We hate doing repetitive things with php, mySQL and the likes. That is why we decided to take on Rails and learn as much as possible, in order to fully harvest its power. Therefore, it would make no sense to reinvent the wheel for no reason. Rails has many people who are working behind the scenes to make it better. In that process, many of them create some very useful plugins, that make our lives a whole lot easier. There is no need to write your own authentication routine, RBAC, messaging system, or even a forum. Take a very close look on the hundred of Rails plugins first. A good starting point is http://agilewebdevelopment.com/, and as always, use a search engine for more :)

3. Understand What a Model, Controller, View, and Helper are

Rails heavily depends on the model view controller (MVC) design pattern. Every one of them has a specific job and jeopardizing them is never a good idea. A controller is responsible for handling Rails requests and passing data from a model to a view. You can think of the controller as a manager between the logic of your program and the actual view that a user actually sees. Generally, a controller should have very few code. It should just execute some functions and retrieve instance variables to be used directly in a view. Moreover, it is used to do redirects with redirect_to and the likes.

A model is where your actual business logic is. The body of your main functions should always lie inside a model that is responsible for handling that data. Since a model operates on data, it’s pretty sensible that a model actually represents a database table and the operations that can be done on that. Always make sure that your functions and core code is inside your models.

A view is where data is represented to the user. You should never (really, never) include logic inside your models. If you feel that you need to include some sort of code inside your views, chances are high that you will be executing more database queries than actually needed. If you feel that you can use a hash instead, do it; although a bit more code to write, it’s the superior choice.

Some people may believe that a helper is the way to elegantly include code in your views. However, that is not really the case. A helper is actually (or should be) sort of a formatting underlying task. For instance, suppose that you have a hash that contains the costs of 4 different products, that you need to present to your view. If you would like to present some of the prices in euros and some in dollars, you could use a helper that would create a string like “this costs 20 dollars” or a string like “this costs 18 euros”, based on the helper function input.

Always put code having this priority in your mind :

1. model

2. helper

3. controller

4. view

4. Yes, Nil and Empty are a Bit Weird in Rails. Hopefully, this section will make it a bit more clear for you.

One of the things that are a bit weird in Rails, is the the way it handles true, false, and nil values. One may think that a false is equal to a nil, like 0 is equal to false in languages like php. However, this is not the case with Rails. Let’s illustrate using rails console :


irb(main):013:0> false.nil?
=> false
irb(main):014:0> true.nil?
=> false
irb(main):015:0> 0.nil?
=> false
irb(main):016:0> [].nil?
=> false
irb(main):017:0> User.find_by_id(1).nil?
=> true
irb(main):018:0> User.find_by_name('hthought').nil?
=> false

This should now make more sense. In Rails, you check whether an object meets a certain condition, using the ? operand like : “1.nil?”. This would check whether 1 is a nil object (would return false, of course). In the examples above, you first notice that true, false, and 0 are not nil objects. Also, an empty hash is still not a nil object. However, trying to find a user that has an id of 1 returns nil if this user does not exist. On the other side, a user with the name ‘hthought’ does exist, and that is why we get a not nil value in the last example. Let’s now take a look at empty? as well :


irb(main):019:0> [].empty?
=> true
irb(main):020:0> "".empty?
=> true
irb(main):021:0> 1.empty?
NoMethodError: undefined method `empty?' for 1:Fixnum
 from (irb):21
irb(main):022:0> "hello".empty?
=> false
irb(main):023:0> "".blank?
=> true
irb(main):024:0> User.find_by_id(1).blank?
=> true

Checking for empty? is like checking whether an array object, like a hash or a string does not have anything in it. A nil object cannot be checked for empty? because it is not an array; that would give us an error. An empty hash or string returns true, as expected. 1.empty? is not correct, because 1 is not an array. Checking for [1].empty? though, is applicable.

Another interesting method is blank?. This one is actually the combination of checking for a nil object or an empty array. Thus, “”.blank? is like “”.empty? and User.find_by_id(1).blank? is like User.find_by_id(1).nil?. Hope this clears things for you.

5. Populate your Database using Fixtures

The folder test/fixtures holds a yml representation for each of your models. Use them to define static data for your database and then use a task to drop, create, migrate and seed your database.

6. When You Are Deeply Messed With Your Associations, It’s Probably Time To Use Scopes

A scope (or a named_scope in previous rails versions), is a way to create ready made relations, that can pretty much simplify some of your model code. Imagine a scenario when you have created a user inventory that contains lots of inventory items. Each inventory item is actually a game item and describes the inventory that holds it. Now, an item can be equipped or not and can be a weapon, gloves, a helmet or anything else. The question is, “What is an efficient way to get a user’s items (or a single item), if they are equipped or not ?

Scopes is a very elegant way to do that. First, you would go to the InventoryItem model and create a scope that describes whether an item is equipped :


scope :equipped, where(:is_equipped => 1).includes(:game_item)

The attribute inventory_item.is_equipped specifies whether an item is equipped and also includes the game_item model within the returned object. If we now execute something like user.inventory_items.equipped, we would receive an array with all the equipped user items. Let’s take it a step further. We just want to receive an equipped helmet, or an equipped weapon. Thus, we create a new scope :


scope :item, lambda { |item_type|
    joins(:game_item).
    where("game_items.item_type = ?", item_type ).
    limit(1)
}

We define a scope named item that is described by a lambda function. This one has an argument based on the item type and joins the game_item model in order to check for that value. We are now able to execute something like “user.equipped.item(‘Weapon’)” to get an equipped weapon. Pretty cool, isn’t it ? :)

7. If You Need Repetitive Non Model Functionality, Use Modules

There are times when we need to do the same things over and over, but in different modules. Moreover, the things we need to do are not really part of a particular model. This is most probably a good time to use a module. Modules are generally loaded from /lib. Be a bit cautious though. In Rails 3, the lib path does not autoload modules. You need to explicitly specify that in application.rb like :


# autoload lib modules
 config.autoload_paths += %W(#{config.root}/lib)

Creating a module is really easy. You can just create an rb file with the name of your module (the name is used to load the module), or create a separate folder and store your module there. Let’s say that you need to create a utilities.rb module (you can omit the class if you like of course) :


module Utilities

class Utils

#get a random number for min,max range
def self.rand_range(min,max)
min + rand(max-min)
end

end

end

From your other models, you just need to “include Utilities” and you can use these functions as if they were part of your model.  But what if we have our module in a folder like “message_modules/private_message.rb” ? You create the module the same way, but you include it like :


include MessageModules::PrivateMessage

Rails converts MessageModules::PrivateMessage to message_modules/private_messag, locates your code and is now ready to use it.

8. Avoid Scaffolding In Your First Projects

Who isn’t aware of the good old create a blog in Rails in 15 minutes video ? That is probably why some of us started to learn Rails in the first place. While this video is really good in showing how quickly things can be done in Rails, it does all these things by scaffolding. While scaffolding is a great way to do CRUD (create, read, update, delete) models, controllers and views really fast, it can confuse a newcomer quite a lot. The reason is that scaffolding creates a whole new premade environment for you. If you are not really comfortable with its internals, it can be a bit devastating. To effectively understand scaffolding, you already need to be a seasoned Rails programmer, know about routes, redirects and more. That is why i would never suggest that somebody begins a project with scaffolding. Better start by creating your models, controllers, views and helpers explicitly and avoid scaffolding for now.

9. Use Partials For Views That Are Used In Many Places

Partials are simply templates that can be included from your main views. A partial can be anywhere inside your views folder. I prefer to create a partials folder and have subfolders for some of my partials. You can even pass variables through partials. However, that is never a good idea, since you are including business logic in your views, if you do that. This could be an include :


<%= render :partial => "partials/attack_display", :locals => { :attack_type => 'monster' } %>

This renders the view that resides in partials/_attack_display.erb and passes an attack_type = ‘monster’ variable (for the sake of this example, but never do that). The code inside _attack_display.erb is now displayed in place of this include.

10. Create Your Routes From Scratch

It’s a very good idea to create your routes yourself. Eventually, you will need to learn how Rails routing works, so it’s better to learn is fast. It’s pretty easy anyway. Do not just use the standard global Rails route for every controller/action/:id but rather include your own ones, even better with scopes like :

scope :path => '/pvp', :controller => :pvp do
    match '/' => :index
    match 'pvp_attack/:id' => :pvp_attack
end

This defines that the pvp_controller is responsible for a call to domain/pvp. Then, for no specified action(/), the index action is called. If domain/pvp/pvp_attack/7361 is called, this is handled by the action pvp_attack of the pvp controller and a param[:id] = 7361 is passed to the action.


Programming Tips For Versatile Coders

Tags: , , , ,

How to create a maze: part 1 of 2

Posted in C++ on March 27th, 2011 by Admin

Creating a random maze, creating a game and creating a program that solves that maze.
C++ Home

Tags: , ,

Today’s gaming news

Posted in Video Game Programming on March 27th, 2011 by Admin

Well I’ve had a good few links today:

EDUCATION:

Paul Curzon‘s name has come up again as someone that is doing excellent work at teaching computer science to schools.  He runs the computer science for fun website which is an attractive starting point for anyone wanting to learn about computers.  There must be more education for computer science in the UK if we are going to continue with our very profitible games and visual effects industry.

MAKING STUFF:

I read about the HackSpace foundation today. If you need to build something and don’t have the facilities maybe this can help.  I will have to keep an eye on this for my Arduino projects.  Only a few more weeks to the MakerFaire 2011 in Newcastle.

PIRACY:

A warning about making your revenue making games open source.  I suppose, just make sure that you make it ABSOLUTELY CLEAR that open source, doesn’t mean free for anyone to make money off.

 

 

 

 


Programming: Robots & Video Games

Tags: , ,

The Visual C++ Weekly Vol. 1 Issue 13 (Mar 26, 2011)

Posted in C++ on March 26th, 2011 by Admin

Read in this issue0:

  • [Herb Sutter] C++0x: We Have Final Draft International Standard!
  • [Parallel Patterns Library] Building Responsive GUI Applications with PPL Tasks
  • [C++ MVP Giovanni Dicanio] Text-to-Speech in C++
  • [Danny Kalev] Detecting Memory Leaks to Improve Performance
  • [C++ MVP Giovanni Dicanio] Checked Iterators
  • [Windows Development] Using Services


Visual C++ Team Blog

Tags: , , , ,