RE: Silverlight fruit basket program developed without Visual Studio

  • From: "Homme, James" <james.homme@xxxxxxxxxxxx>
  • To: "programmingblind@xxxxxxxxxxxxx" <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 18 May 2011 07:18:05 -0400

Hi,
This is up on 
http://fruitbasketdemos.org/content/silverlight-fruit-basket-program-developed-without-visual-studio
 now.

Jim

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx 
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Jamal Mazrui
Sent: Tuesday, May 17, 2011 10:58 PM
To: blindwebbers@xxxxxxxxxxxxxxx; programmingblind; Program-l
Subject: Silverlight fruit basket program developed without Visual Studio

 From the archive
http://EmpowermentZone.com/sl_fruit.zip

This fruit basket program is developed with C# and Microsoft
Silverlight.  The archive in zip format, FruitBasket.xap, is hosted in a
web page, FruitBasket.htm, which serves as a wrapper for the app.  The
Silverlight 4 runtime is required on the client computer.  Supported web
browsers include Internet Explorer, Firefox, and Safari.

The free Silverlight 4 SDK is available from the web site
http://silverlight.net

The batch file build.bat invokes the C# compiler of the .NET Framework 4
to produce the assembly FruitBasket.dll from the source code
FruitBasket.cs.  The response file, Silverlight.rsp, directs the
compiler to build with Silverlight components rather than desktop
components of the .NET Framework.  The The free 7z.exe utility then
creates FruitBasket.xap from FruitBasket.dll and AppManifest.xaml.  That
XML file tells the Silverlight runtime what assembly and type will be
the entry point of the app.  The batch file finally opens the
FruitBasket.htm with the default browser for testing the app.

One surprise about the Silverlight API was the absense of a property for
specifying the default button in a form.  Programmatically clicking a
button was also more involved than expected.  Some additional code was
thus needed so that the Enter key in the edit box would invoke the Add
button.

Otherwise, however, this fruit basket program was deliberately coded in
a minimalist manner in order to highlight the key ingrediants of a
Silverlight app without extraneous clutter.  A Visual Studio project of
the same functionality contains significantly more files, code, and
complexity.  Of course, an IDE also has benefits, but this shows that it
is possible to develop Silverlight apps with a text editor and
command-line tools.

A large collection of text tutorials about Silverlight development (and
the dynamic languages IronPython and IronRuby) is available at
http://EmpowermentZone.com/sl_doc.zip

Screen readers vary significantly in their client-side support for
Silverlight accessibility, which is based on an API called User
Interface Automation (UIA).  It may be necessary to manually turn off a
virtual or browse mode in order to interact with the app.  To try it,
open the embedding HTML file, either locally after unzipping the
archive, or via the following web address:
http://EmpowermentZone.com/FruitBasket.htm

The archive will soon be available on
http://FruitBasketDemos.org

For convenient reference, the FruitBasket.cs code is also pasted below.

Jamal Mazrui



/*
Fruit basket program in Silverlight without Visual Studio
Public domain by Jamal Mazrui
May 17, 2011
*/

// Import namespaces
using System;
using System.Net;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml;

// Define namespace
namespace FruitBasket {

// Define class
public class App: Application {

// Define entry point of program
public App() {
this.Startup += HandleStartup;
} // App Constructor

void HandleStartup(object sender, StartupEventArgs eventArgs) {
// Create controls;
var lblFruit = new TextBlock {Text = "Fruit:"};
var txtFruit = new TextBox();
var btnAdd = new Button {Content = "Add"};
var lblBasket = new TextBlock {Text = "Basket:"};
var lstBasket = new ListBox{IsTabStop = true};
var btnDelete = new Button {Content = "Delete"};

// Define Add event handler;
btnAdd.Click += (o, e) => {
var sFruit = txtFruit.Text;
if (sFruit == "") MessageBox.Show("Alert - No fruit to add!");
else {
lstBasket.Items.Add(sFruit);
txtFruit.Text = "";
lstBasket.SelectedIndex = lstBasket.Items.Count - 1;
}
};

// Define Delete event handler;
btnDelete.Click += (o,e) => {
var iFruit = lstBasket.SelectedIndex;
if (iFruit == -1) MessageBox.Show("Alert - No fruit to delete!");
else {
lstBasket.Items.RemoveAt(iFruit);
if (iFruit == lstBasket.Items.Count) iFruit--;
if (iFruit >=0) lstBasket.SelectedIndex = iFruit;
}
};

// Make Enter in the TextBox invoke the Add button
txtFruit.KeyDown += (o, e) => {
if (e.Key == Key.Enter) {
var peer = new ButtonAutomationPeer(btnAdd);
var provider = (IInvokeProvider) peer;
provider.Invoke();
}
};

// Complete layout

// Horizontal panel with TextBox and Add button
var pnlAdd = new StackPanel {Orientation = Orientation.Horizontal};
foreach (var widget in new UIElement[] {lblFruit, txtFruit, btnAdd})
pnlAdd.Children.Add(widget);

// Horizontal panel with ListBox and Delete button
var pnlDelete = new StackPanel {Orientation = Orientation.Horizontal};
foreach (var widget in new UIElement[] {lblBasket, lstBasket,
btnDelete}) pnlDelete.Children.Add(widget);

// Vertical panel containing the two horizontal panels
var pnlMain = new StackPanel {Orientation = Orientation.Vertical};
foreach (var widget in new UIElement[] {pnlAdd, pnlDelete})
pnlMain.Children.Add(widget);

// Set the RootVisual container of the app, and initial focus to the TextBox
this.RootVisual = pnlMain;
txtFruit.Focus();
} // Handlestartup method
} // App class
} // FruitBasket namespace
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


This e-mail and any attachments to it are confidential and are intended solely 
for use of the individual or entity to whom they are addressed.  If you have 
received this e-mail in error, please notify the sender immediately and then 
delete it.  If you are not the intended recipient, you must not keep, use, 
disclose, copy or distribute this e-mail without the author's prior permission. 
 The views expressed in this e-mail message do not necessarily represent the 
views of Highmark Inc., its subsidiaries, or affiliates.
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

Other related posts: