The following example shows simple startup code for IronPython, IronRuby, and Managed JScript. In each case, the example defines an App class with a start method, creates an instance of the class, and calls the start method.
The example uses an app.xaml file, which is the same for all languages. The file is listed following the code.
On initialization, the example uses the Application..::.Current property to get the DynamicApplication object, and then uses the LoadRootVisual method to load a UserControl from the app.xaml file, which is located in the same folder as the entry point code. In the start method, the example sets the text of a TextBlock control named Message.
For information on running dynamic language code using Chiron.exe, see Dynamic Languages in Silverlight 2.
# ---- IronPython ----
from System.Windows import Application
from System.Windows.Controls import UserControl
class App:
def __init__(self):
self.scene = Application.Current.LoadRootVisual(UserControl(), "app.xaml")
def start(self):
# TODO: Replace this with your application start logic.
self.scene.Message.Text = "Welcome to Silverlight and IronPython."
App().start()
# ---- IronRuby ----
include System::Windows
include System::Windows::Controls
class App
def initialize
@scene = Application.Current.LoadRootVisual(UserControl.new(), "app.xaml")
end
def start
# TODO: Replace this with your application start logic.
@scene.find_name('Message').text = "Welcome to Silverlight and IronRuby."
end
end
App.new.start
// ---- Managed JScript ----
Import("System.Windows.Application")
Import("System.Windows.Controls.UserControl")
function App() {
this.scene = Application.Current.LoadRootVisual(new UserControl(), "app.xaml")
}
App.prototype.start = function() {
// TODO: Put application logic here.
this.scene.Message.Text = "Welcome to Silverlight and Managed JScript."
}
app = new App
app.start()
The app.xaml file contains the following XAML:
<UserControl
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="System.Windows.Controls.UserControl"
x:Name="Page"
>
<TextBlock
x:Name="Message" TextWrapping="Wrap" Foreground="Black" >
</TextBlock>
</UserControl>