Getting Started with Windows Phone Apps in RemObjects C#

This series of steps requires the use of RemObjects C# within Visual Studio. You also need to install the Windows Phone SDK 8.0 on Windows 8. It takes some time to install but then does work quite speedily.

The result will be a program in which you can enter a forename, be greeted personally and use a button to clear the data. The following screenshot shows the program in action in the emulator (which is installed with the Windows Phone SDK). We captured and saved the screenshot using one of the additional tools of the emulator.

Phone App working in Emulator

Tip: The emulator takes some time to start up, so when you have tested the current version of your code it is sensible to stop debugging (with Shift+F5 or by clicking on the red square icon) without closing the emulator.

The layout uses a StackPanel to place the other components immediately under each other.

  1. Select menu item File > New > Project (or type Ctrl+Shift+N), highlight the Windows Phone Application (within Visual C#) and name the project PhoneApp_GreetingCS. Click the OK button. Accept the default OS (Windows Phone OS 8.0).
  2. Delete all of the outer Grid and contents in MainPage.xaml.
  3. Double click on StackPanel in the Toolbox and set HorizontalAlignment="Stretch" in the XAML code. Remove the height and width properties.
  4. Double click on TextBlock in the Toolbox and change the Text property from TextBlock to Greeting. Add to the properties in the XAML code these properties: HorizontalAlignment="Center" FontSize="36" FontWeight="Bold" Foreground="DarkOliveGreen"
  5. Double click on Button in the Toolbox, name it btnClear, change the Content property from Button to Clear. Manually add to its XAML properties Click="btnClear_Click"
  6. In the Oxygene code in MainPage.xaml.pas add this method under the MainPage constructor.
         public void btnClear_Click(System.Object sender, RoutedEventArgs e)
         {
           txtbGreeting.Text = "";
           tbForename.Text = "";
           btnClear.IsEnabled = false;
         }
    
  7. Double click on TextBlock in the Toolbox and change the Text property from TextBlock to "Please enter your forename in the box below".
  8. Double click on TextBox in the Toolbox, name the new TextBox tbForename and remove the Text property "TextBox". Manually add to the XAML properties KeyDown="tbForename_KeyDown".
  9. Add this code below the button click method:
         public void tbForename_KeyDown(System.Object sender, System.Windows.Input.KeyEventArgs e)
         {
           btnClear.IsEnabled = true;
           if (e.Key == System.Windows.Input.Key.Enter) 
             txtbGreeting.Text = "Hello, " + tbForename.Text + "!";
         }
  10. Double click on TextBlock in the Toolbox, name it txtbGreeting and remove the Text property "TextBlock". Add to its properties: FontSize="36" Foreground="Blue"
  11. Try it!

The complete C# code, after removing unnecessary comments and using statements follows.

using System.Windows; using Microsoft.Phone.Controls; namespace PhoneAppGreetingCS { public partial class MainPage : PhoneApplicationPage { public MainPage() { InitializeComponent(); } public void btnClear_Click(System.Object sender, RoutedEventArgs e) { txtbGreeting.Text = ""; tbForename.Text = ""; btnClear.IsEnabled = false; } public void tbForename_KeyDown(System.Object sender, System.Windows.Input.KeyEventArgs e) { btnClear.IsEnabled = true; if (e.Key == System.Windows.Input.Key.Enter) txtbGreeting.Text = "Hello, " + tbForename.Text + "!"; } } }

See our original Oxygene version for the XAML code and change x:Class="PhoneAppGreeting.MainPage" to x:Class="PhoneAppGreetingCS.MainPage".

Selection by RadioButtons and LongListSelector

For this demonstration we supply the Oxygene and XAML code. To obtain a working version, start a new Windows PhoneApp named PhoneAppSelectionCS and paste the Oxygene code below into MainPage.xaml.pas and the XAML code into MainPage.xaml. If you want to start from scratch, see the steps above if necessary to learn how to add components to the form and to change their properties.

using System; using System.Collections.Generic; using System.Windows; using System.Windows.Controls; using Microsoft.Phone.Controls; using System.Windows.Media; namespace PhoneAppSelectionCS { public partial class MainPage: PhoneApplicationPage { private List<int> Sizes = new List<int>{24, 36, 48, 60, 72}; String MessageColour = "Yellow"; String MessageSize= "24"; public MainPage() { InitializeComponent(); llsFontSize.ItemsSource = Sizes; llsFontSize.FontSize = 24; } public void rbClick(System.Object sender, System.Windows.RoutedEventArgs e) { RadioButton rbSelected = sender as RadioButton; switch (rbSelected.Name) { case "rbRed": MessageColour = "Red"; txtbMessage.Foreground = new SolidColorBrush(Colors.Red); break; case "rbBlue": MessageColour = "Blue"; txtbMessage.Foreground = new SolidColorBrush(Colors.Blue); break; case "rbGreen": MessageColour = "Green"; txtbMessage.Foreground = new SolidColorBrush(Colors.Green); break; } txtbMessage.Text = MessageColour + " " + MessageSize; } public void llsFontSize_SelectionChanged(System.Object sender, System.Windows.RoutedEventArgs e) { txtbMessage.FontSize = (int) llsFontSize.SelectedItem; MessageSize = txtbMessage.FontSize.ToString(); txtbMessage.Text = MessageColour + " " + MessageSize; } } }

See the Oxygene version for a screenshot and the XAML code. Change x:Class="PhoneAppSelection.MainPage" to x:Class="PhoneAppSelectionCS.MainPage".