Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to add a property to the WPF web browser to allow me to use NavigateToString at runtime, but I'm getting the exception:

SystemError: Cannot set unknown member '{clr-namespace:WebBrowserHelper;Assembly=helpers}WebBrowserHelper.Body'.

I have a working version of this in a C# assembly, but I would like to know how it can be done using IronPython.

My ns declaration looks like this:

xmlns:helpers="clr-namespace:WebBrowserHelper;Assembly=helpers"

and it's used like this:

<WebBrowser helpers:WebBrowserHelper.Body="{Binding html}" />

This is the IronPython code:

import clr

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

from System.Windows import (
DependencyObject, DependencyProperty
)

class WebBrowserHelper(DependencyObject):
    _Body = None

    def __new__(cls):
        if notWebBrowserHelper._Body:
            WebBrowserHelper._Body = DependencyProperty.RegisterAttached(
                "Body", clr.GetClrType(str), clr.GetClrType(WebBrowserHelper), PropertyMetadata(WebBrowserHelper.OnBodyChanged))
        return DependencyObject.__new__(cls)

    def getBody(self):
        return self.GetValue(WebBrowserHelper._Body)

    def setBody(self, value):
        self.SetValue(WebBrowserHelper._Body, value)

    @staticmethod
    def OnBodyChanged(dependancyObject, eventArgs):
        dependancyObject.NavigateToString(eventArgs.NewValue)

    Body = property(getBody, setBody)
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.