IronPython & Silverlight o MY!
by kongkoro on Aug.07, 2009, under silverlight
This is a sample application that I made using Blend and IronPython!! The Gui was made in Blend, and the event listener code for the button was written in IronPython! This example was based on a tutorial by Tim Heuer, and I wanted to see if I could implement it with Iron Python and I did. It’s nice to see the Dynamic Language Runtime in action, and being able to interact with XAML from python is GRrrrEeaaTTt.
My app.py code:
from System.Windows.Controls import ( UserControl, Grid, RowDefinition, ColumnDefinition, Button, TextBlock, TextBox )
xaml = Application.Current.LoadRootVisual(UserControl(), “app.xaml”)
root = xaml.LayoutRoot
#the Click Method
def onClick(s,e):
root.outText.Text = root.inText.Text
#add onClick to btn event handler
root.btnText.Click += onClick
My app.xaml code:
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″ xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″
x:Class=”System.Windows.Controls.UserControl”
>
<Grid x:Name=”LayoutRoot” Background=”White” ShowGridLines=”True”>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBox Margin=”8″ Grid.Row=”0″ Text =”Write Here” TextWrapping=”Wrap” x:Name=”inText” FontSize=”16″ TextAlignment=”Center”/>
<Button Margin=”8″ Grid.Row=”1″ Content=”Click Me!” x:Name=”btnText”/>
<TextBlock Margin=”8″ Grid.Row=”2″ TextWrapping=”Wrap” x:Name=”outText” TextAlignment=”Center”/>
</Grid>
</UserControl>
The complete project is available here
