<div>I write a blog about this topic, link:<a href="http://www.cnblogs.com/redmoon/archive/2008/03/08/1096331.html">http://www.cnblogs.com/redmoon/archive/2008/03/08/1096331.html</a></div>
<div>It is be writed in Chinese.<br><br></div>
<div class="gmail_quote">On Tue, Mar 11, 2008 at 8:15 AM, Jimmy Schementi &lt;<a href="mailto:Jimmy.Schementi@microsoft.com">Jimmy.Schementi@microsoft.com</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Yep, that&#39;s the way to do it =)<br><br>Ideally, this would be abstracted away in a silverlight.py utility module ... which I see as largely community driven ... so feel free to share anything you think would be great to reuse across all python Silverlight apps.<br>
<font color="#888888"><br>~js<br></font>
<div class="Ih2E3d"><br>&gt; -----Original Message-----<br>&gt; From: <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-">users-</a><br></div>
<div>
<div></div>
<div class="Wj3C7c">&gt; <a href="mailto:bounces@lists.ironpython.com">bounces@lists.ironpython.com</a>] On Behalf Of Dino Viehland<br>&gt; Sent: Monday, March 10, 2008 5:12 PM<br>&gt; To: Discussion of IronPython<br>&gt; Subject: Re: [IronPython] how to use IronPython in Silverlight 2<br>
&gt;<br>&gt; That&#39;s just Application.Current.RootVisual = myCanvas<br>&gt;<br>&gt; This is what I&#39;ve been doing in my own Silverlight experiments, but I<br>&gt; suck at using XAML and Blend :)<br>&gt;<br>&gt; -----Original Message-----<br>
&gt; From: <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-">users-</a><br>&gt; <a href="mailto:bounces@lists.ironpython.com">bounces@lists.ironpython.com</a>] On Behalf Of Michael Foord<br>
&gt; Sent: Monday, March 10, 2008 4:32 PM<br>&gt; To: Discussion of IronPython<br>&gt; Subject: Re: [IronPython] how to use IronPython in Silverlight 2<br>&gt;<br>&gt; Jimmy Schementi wrote:<br>&gt; &gt;<br>&gt; &gt; To load a XAML file and set the RootVisual, you can do this:<br>
&gt; &gt;<br>&gt; &gt; Application.Current.LoadRootVisual(&quot;file.xaml&quot;)<br>&gt; &gt;<br>&gt; &gt; It&#39;s how we do it in the python samples on<br>&gt; <a href="http://dynamicsilverlight.net/" target="_blank">http://dynamicsilverlight.net</a><br>
&gt; &gt;<br>&gt;<br>&gt; Suppose you don&#39;t want to load a XAML file - how do you do that (but<br>&gt; say<br>&gt; set a &#39;Canvas&#39; instance you have created programatically) ?<br>&gt;<br>&gt; Michael<br>&gt;<br>
&gt;<br>&gt; &gt; ~Jimmy<br>&gt; &gt;<br>&gt; &gt; *From:* <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a><br>&gt; &gt; [mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>] *On Behalf Of *Dino<br>
&gt; Viehland<br>&gt; &gt; *Sent:* Friday, March 07, 2008 11:25 AM<br>&gt; &gt; *To:* Discussion of IronPython<br>&gt; &gt; *Subject:* Re: [IronPython] how to use IronPython in Silverlight 2<br>&gt; &gt;<br>&gt; &gt; One problem is that XamlReader.Load takes the string of XAML and not<br>
&gt; a<br>&gt; &gt; filename. But there&#39;s something about the XAML that isn&#39;t working<br>&gt; &gt; right too. I&#39;m no XAML expert but simplifying it to the code below<br>&gt; &gt; works, you can probably build something up from that. Personally for<br>
&gt; &gt; my Silverlight hacking I&#39;ve just been building up the tree<br>&gt; &gt; programmatically from Python code even though that&#39;s uncool J.<br>&gt; &gt;<br>&gt; &gt; from System.Windows import Application<br>
&gt; &gt;<br>&gt; &gt; from System.Windows.Markup import XamlReader<br>&gt; &gt;<br>&gt; &gt; Application.Current.RootVisual = XamlReader.Load(&quot;&quot;&quot;<br>&gt; &gt;<br>&gt; &gt; &lt;Canvas Width=&quot;100&quot; Height=&quot;100&quot;<br>
&gt; &gt; xmlns=&quot;<a href="http://schemas.microsoft.com/client/2007" target="_blank">http://schemas.microsoft.com/client/2007</a>&quot;<br>&gt; &gt; xmlns:x=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml" target="_blank">http://schemas.microsoft.com/winfx/2006/xaml</a>&quot;&gt;<br>
&gt; &gt;<br>&gt; &gt; &lt;TextBlock FontSize=&quot;30&quot; Text=&quot;hello world&quot;/&gt;<br>&gt; &gt;<br>&gt; &gt; &lt;/Canvas&gt;&quot;&quot;&quot;)<br>&gt; &gt;<br>&gt; &gt; *From:* <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a><br>
&gt; &gt; [mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>] *On Behalf Of *Kevin Chu<br>&gt; &gt; *Sent:* Friday, March 07, 2008 9:32 AM<br>&gt; &gt; *To:* Discussion of IronPython<br>
&gt; &gt; *Subject:* Re: [IronPython] how to use IronPython in Silverlight 2<br>&gt; &gt;<br>&gt; &gt; hi Dino<br>&gt; &gt;<br>&gt; &gt; Thanks for your reply.<br>&gt; &gt;<br>&gt; &gt; But I try my sample (look attachment), It can&#39;t run! Is my code<br>
&gt; mistake ?<br>&gt; &gt;<br>&gt; &gt; *IronPython code:*<br>&gt; &gt;<br>&gt; &gt; from System.Windows import Application<br>&gt; &gt; from System.Windows.Markup import XamlReader<br>&gt; &gt;<br>&gt; &gt; class App:<br>
&gt; &gt; def __init__(self):<br>&gt; &gt; Application.Current.RootVisual = XamlReader.Load(&quot;app.xaml&quot;)<br>&gt; &gt; self.scene = Application.Current.RootVisual.grid<br>&gt; &gt; def start(self):<br>&gt; &gt; # TO DO: Replace this with your application start logic.<br>
&gt; &gt; self.scene.message.Content = &quot;Welcome to Silverlight and IronPython!&quot;<br>&gt; &gt;<br>&gt; &gt; App().start()<br>&gt; &gt;<br>&gt; &gt; *XAML code:*<br>&gt; &gt;<br>&gt; &gt; &lt;UserControl x:Class=&quot;System.Windows.Controls.UserControl&quot;<br>
&gt; &gt; xmlns=&quot;<a href="http://schemas.microsoft.com/client/2007" target="_blank">http://schemas.microsoft.com/client/2007</a>&quot;<br>&gt; &gt; xmlns:x=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml" target="_blank">http://schemas.microsoft.com/winfx/2006/xaml</a>&quot;&gt;<br>
&gt; &gt;<br>&gt; &gt; &lt;Grid x:Name=&quot;grid&quot; Background=&quot;White&quot;&gt;<br>&gt; &gt; &lt;TextBlock x:Name=&quot;message&quot; FontSize=&quot;30&quot; /&gt;<br>&gt; &gt; &lt;/Grid&gt;<br>&gt; &gt;<br>&gt; &gt; &lt;/UserControl&gt;<br>
&gt; &gt;<br>&gt; &gt; On Fri, Mar 7, 2008 at 11:55 AM, Dino Viehland<br>&gt; &gt; &lt;<a href="mailto:dinov@exchange.microsoft.com">dinov@exchange.microsoft.com</a> &lt;mailto:<a href="mailto:dinov@exchange.microsoft.com">dinov@exchange.microsoft.com</a>&gt;&gt;<br>
&gt; &gt; wrote:<br>&gt; &gt;<br>&gt; &gt; You&#39;ll need to download the Silverlight 2 SDK. After installing that<br>&gt; &gt; you&#39;ll get all the necessary components installed into something like<br>&gt; &gt; C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Libraries\Client.<br>
&gt; &gt; Also installed is an extremely useful tool called Chiron which you&#39;ll<br>&gt; &gt; find somewhere around C:\Program Files\Microsoft<br>&gt; &gt; SDKs\Silverlight\v2.0\Tools\Chiron. Chiron can take your .py file and<br>
&gt; &gt; produce a .xap which includes the IronPython &amp; DLR DLLs using the<br>&gt; &gt; /zipdlr command line option. You can also use it to serve http<br>&gt; &gt; requests and automatically serve up the .xap and let you just edit<br>
&gt; the<br>&gt; &gt; files.<br>&gt; &gt;<br>&gt; &gt; So once you&#39;re ready to make your xap the directory you point at<br>&gt; &gt; should contain a .py file (I&#39;m not sure what the multi .py file<br>&gt; &gt; experience is like, but w/ a single file the it doesn&#39;t seem the name<br>
&gt; &gt; matters). The simplest thing to put in there is:<br>&gt; &gt;<br>&gt; &gt; from System.Windows import Application<br>&gt; &gt;<br>&gt; &gt; from System.Windows.Markup import XamlReader<br>&gt; &gt;<br>&gt; &gt; Application.Current.RootVisual = XamlReader.Load(&quot;someXaml&quot;)<br>
&gt; &gt;<br>&gt; &gt; You can see this from the Ruby perspective over at<br>&gt; &gt; <a href="http://www.iunknown.com/2008/03/dynamic-silverl.html" target="_blank">http://www.iunknown.com/2008/03/dynamic-silverl.html</a><br>
&gt; &gt;<br>&gt; &gt; There&#39;s various options on how to deploy the DLLs, and you can get<br>&gt; &gt; into manifest files to deploy additional DLLs, but hopefully that&#39;ll<br>&gt; &gt; get you started.<br>&gt; &gt;<br>
&gt; &gt; *From:* <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a><br>&gt; &gt; &lt;mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>&gt;<br>
&gt; &gt; [mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a><br>&gt; &gt; &lt;mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>&gt;] *On Behalf Of *Kevin Chu<br>
&gt; &gt; *Sent:* Thursday, March 06, 2008 7:39 PM<br>&gt; &gt; *To:* Discussion of IronPython<br>&gt; &gt; *Subject:* [IronPython] how to use IronPython in Silverlight 2<br>&gt; &gt;<br>&gt; &gt; Silverlight 2 beta1 tools for VS2008 only create C# code file,<br>
&gt; &gt;<br>&gt; &gt; How to create a IronPython code file?<br>&gt; &gt;<br>&gt; &gt; --<br>&gt; &gt; Once in a Redmoon<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; _______________________________________________<br>&gt; &gt; Users mailing list<br>
&gt; &gt; <a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a> &lt;mailto:<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a>&gt;<br>&gt; &gt; <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; --<br>&gt; &gt; Once in a Redmoon<br>&gt; &gt;<br>&gt; &gt; ---------------------------------------------------------------------<br>&gt; ---<br>&gt; &gt;<br>&gt; &gt; _______________________________________________<br>
&gt; &gt; Users mailing list<br>&gt; &gt; <a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>&gt; &gt; <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
&gt; &gt;<br>&gt;<br>&gt; _______________________________________________<br>&gt; Users mailing list<br>&gt; <a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>&gt; <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
&gt; _______________________________________________<br>&gt; Users mailing list<br>&gt; <a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>&gt; <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
_______________________________________________<br>Users mailing list<br><a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br><a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Once in a Redmoon