[IronPython] Hosting IronPython in a Silverlight App
Michael Foord
fuzzyman at voidspace.org.uk
Mon Sep 3 23:23:32 CEST 2007
Hello all,
I'm experimenting with hosting IronPython in a silverlight (1.1 alpha
refresh) app.
When I write C# code that uses the PythonEngine it works fine when
access *from IronPython code*.
If I use the same code as 'code behind', then it throws an exception
"The method or operation is not implemented."
(At the line "PythonEngine pe = PythonEngine.CurrentEngine;")
The code is:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using IronPython.Hosting;
using Microsoft.Scripting;
namespace EmbeddedWithCodeBehind
{
public partial class Page : Canvas
{
public void Page_Loaded(object o, EventArgs e)
{
// Required to initialize variables
InitializeComponent();
try
{
PythonEngine pe = PythonEngine.CurrentEngine;
string code = "lambda x: x.upper()";
Function<string, string> func =
pe.EvaluateAs<Function<string, string>>(code);
string x = "i'm talking loudly";
string result = func(x);
textBlock.Text = result;
}
catch (Exception ex)
{
textBlock.Text = ex.Message;
}
}
}
}
The XAML is:
<Canvas x:Name="parentCanvas"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Loaded="Page_Loaded"
x:Class="EmbeddedWithCodeBehind.Page;assembly=ClientBin/EmbeddedWithCodeBehind.dll"
Width="640"
Height="480"
Background="White"
>
<TextBlock x:Name="textBlock"></TextBlock>
</Canvas>
Everything else is the default from an Orcas beta 2 new Silverlight project.
Anyone got any clues as to what is happening?
Thanks
Michael Foord
http://www.ironpython.info/
More information about the Ironpython-users
mailing list