[Ironpython-users] Hosting ironpyhon in silverlight , get Couldnot add reference to assembly System.Windows.Controls error

Jimmy Schementi jschementi at gmail.com
Thu Jul 28 19:55:19 CEST 2011


On Thu, Jul 28, 2011 at 12:42 PM, zdong <zdong at rliansoft.com> wrote:
> dear jimmy
>
> Acturally i want to create instance of StackPanel,TextBlock ect. That been
> widly known as silverlight standard framework element in
> system.windows.controls. If i directly use stackins=StackPanel() it's seems
> could not found StackPanel class . So that's way i want to import
> system.windows.controls namespace.

See http://msdn.microsoft.com/en-us/library/system.windows.controls.stackpanel(v=vs.95).aspx).

While System.Windows.Controls is the namespace where StackPanel and
TextBlock are named in, they are located in the System.Windows
assembly, which is in System.Windows.dll. .NET assemblies are
references with clr.AddReference, which then allows you to import the
namespaces from that assembly as if they where Python modules.

So here's how you'd create a StackPanel in Silverlight using IronPython:

import clr
clr.AddReference("System.Windows")
from System.Windows.Controls import StackPanel, TextBlock

s = StackPanel()
s.Children.Add(TextBlock(Text="Block1"))
s.Children.Add(TextBlock(Text="Block2"))


More information about the Ironpython-users mailing list