Home > Uncategorized > PhoneGap for Windows Phone 7

PhoneGap for Windows Phone 7

Not exactly phonegap… but an easy way to create WP7 (Windows Phone 7) apps without any .NET / XAML / Silverlight knowledge.

Basically, I created a XAML front end as follows:

<phone:PhoneApplicationPage     x:Class=”WebBrowserControl.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”>        <phone:WebBrowser x:Name=”Browser1″ IsScriptEnabled=”True” Loaded=”Browser1_Loaded”                       >              </phone:WebBrowser>    </phone:PhoneApplicationPage>

Then, the MainPage.Xaml.cs file contains:

using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Net;using System.Reflection;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;
namespace WebBrowserControl{    public partial class MainPage : PhoneApplicationPage    {        // Constructor        public MainPage()        {            InitializeComponent();                   }
private void Browser1_Loaded(object sender, RoutedEventArgs e)        {            var _assembly = Assembly.GetExecutingAssembly();            var _textStreamReader = new StreamReader(_assembly.GetManifestResourceStream(“WebBrowserControl.Index.html”));            var strHtml = _textStreamReader.ReadToEnd();            Browser1.NavigateToString(strHtml);        }
}}

 

Then Index.Html contains the following:

 

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN””http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”><html xmlns=”http://www.w3.org/1999/xhtml”&gt; <head> <title>Javascript Evalulator</title> <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />         <meta name=”viewport” content=”width=400; user-scalable=no”;         </head> <body sytle=”font-family: Arial, Helvetica, sans-serif;”> <b>Javascript:</b><br> <textarea id=”taJS” rows=”7″ cols=”27″></textarea> <p align=”right”> <a href=”javascript:evaluate();”>Evaluate</a> </p> <b>Result:</b><br> <textarea id=”taResult” rows=”5″ cols=”27″></textarea>        <script language=”javascript”>            function evaluate() {                var JS = document.getElementById(“taJS”);                var Result = document.getElementById(“taResult”);                Result.value = eval(JS.value);            }        </script> </body></html>

 

In order to get a 2/way communication between the WebBrowserControl / Javascript and C#, then The ScriptNotify Event could be used, along with InvokeScript.

Pity the emulator was too slow to see this working properly…

 

 

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: