Playing with Ironpython and Silverlight

Posted by Salvatore Di Dio On jeudi 22 décembre 2011 0 commentaires
Ironpython plays nicely with Silverlight, especially when using
Gestalt.

Here is how I manage to pass arguments to a 'click event' handler,
assuming you have a button whith an id equal to 'Button1'

<script type="text/python">
        import System
        from System import EventHandler
        class Person(object):
            def __init__(self, name):
                self.name = name
                self.greeted = False        
        def GreetHandler(p):
            def SayHello(s,e):
                if not p.greeted:
                    window.Alert("Hello " + p.name)                    
                else:                    
                    window.Alert("Happy to see you again  " + p.name)
                p.greeted = not p.greeted        
            return SayHello
        p = Person("PAUL")
        document.Button1.AttachEvent('onclick',EventHandler(GreetHandler(p)))
</script>

0 commentaires: