Friday, January 29, 2010

WPF Dependency Properties in IronPython

One of the best features added to WPF are Dependency Properties. Dependency properties use a combination of a property and a static field (a class field in python).

As follows you will find an example:

import clr

clr.AddReference("WindowsBase")
clr.AddReference("PresentationCore")
clr.AddReference("PresentationFramework")

from System.Windows import (
DependencyObject, DependencyProperty
)


class Planning(DependencyObject):

_sessionProperty = None

def __new__(cls):
if not Planning._sessionProperty:
Planning._sessionProperty = DependencyProperty.Register(
"session", clr.GetClrType(Session), clr.GetClrType(Planning))
return DependencyObject.__new__(cls)

def getSession(self):
return self.GetValue(Planning._sessionProperty)

def setSession(self, value):
self.SetValue(Planning._sessionProperty, value)

session = property(getSession, setSession)

0 comments: