How do I bind to my DLR type?

Jun 15, 2009 at 10:16 PM
Edited Jun 16, 2009 at 1:32 AM

I'm just getting my feet wet with DLR in SL.  Basically I'm trying to define a class (that implements INotifyPropertyChanged) in python that I can new up and bind in native SL.

Here's my simple python class:
class pyclass:
    def __init__(self):
        self._seeds = "foo_pyclass"

    def __getSeeds(self):
        return self._seeds

    def __setSeeds(self,value):
        self._seeds = value

    Seeds = property(
        fget= __getSeeds,
        fset= __setSeeds

My XAML is pretty trivial:
<Grid x:Name="LayoutRoot">
<TextBox x:Name="it" Text="{Binding Seeds}"></TextBox>

and my page's load:
Dim setup = Python.CreateRuntimeSetup(Nothing)
setup.HostType = GetType(Microsoft.Scripting.Silverlight.BrowserScriptHost)
setup.Options("SearchPaths") = New String() {String.Empty}

Dim runtime = New ScriptRuntime(setup)
Dim pe = Python.GetEngine(runtime)
' Load platform assemblies so you don't need to call LoadAssembly in script code.

Dim scope = pe.CreateScope
Dim source = pe.CreateScriptSourceFromString(code, Microsoft.Scripting.SourceCodeKind.Statements)

Dim someClass = pe.GetVariable(scope, "pyclass")
Dim t = pe.Operations.CreateInstance(someClass)

LayoutRoot.DataContext = t

But, I'm not seeing it work. However, if I do the same with poco, it works fine:

Dim t as New poco()
LayoutRoot.DataContext = t

Public Class poco
    Public ReadOnly Property Seeds() As String
            Return "foo_poco"
        End Get
    End Property
End Class



Jun 16, 2009 at 5:18 PM

I just read this thread from '08 with a similar question for objects from Ruby: However, I was hoping since that was a year ago, the ".net interop" work was done :)  This blog post shows it working from WPF So, what am I missing? Thank you.

Jun 24, 2009 at 12:28 AM

There is no difference between Silverlight and WPF WRT the major hosting API surface area. The article was written in February, and since then that method has been renamed to "CreateInstance": Operations.CreateInstance(someClass) will do the trick.

Jun 29, 2009 at 5:06 PM

Thank you for the reply. However, in my original code above, I am using the new "CreateInstance" but it's not working in Silverlight. It compiles, it runs, but it doesn't bind. Binding to a poco works fine.

I think I'm missing some basic point, but I can't see it. Note: In my code, I'm not running it through Chrion. My SL3 app just references the DL assemblies to be included. Also, in my code, the managed code is setting up the bindning which is slightly different than this example where the bidning is done in python.


Any help appreciated.

Jun 29, 2009 at 5:17 PM

I believe the bit I'm missing pertains to __clrtype__ support to allow SL to reflect on the properties of my dynamic class.,category,__clrtype__.aspx