Re: [Python.NET] Can a python class passed back to .Net

Tony Roberts <[email protected]>
Newsgroups gmane.comp.python.dotnet
Message-ID <CA+XbcsaYiiR=VqRFFVj1jCtQHaM2d0GDpc7sqyJ+dkQ_K5+z2A@mail.gmail.com>
You have to decorate the methods you want to expose to .net with the
clrmethod decorator, e.g.

class MyClass(IInterface):
    @clrmethod(int, [str])
    def overridden_method(self, x):
        return len(x)

The parameters to the clrmethod decorator are the method return type and
argument types. You can expose properties similarly using the clrproperty
decorator.

See runtime/resources/clr.py for details.

regards,
Tony


On Wed, Mar 16, 2016 at 9:29 PM Hansong Huang <[email protected]> wrote:

> This might be an obvious problem out of my lack of understanding how
> Python.Net work.
>
> I am exploring the possibility of program WPF ViewModel.
>
> After resolving the problem inheriting .Net interface class,
>
> class ViewModel(System.ComponentModel.INotifyPropertyChanged):
>     __namespace__ = "WPFPy"
> ....
>
> class MyViewModel(ViewModel):
> ....  here to implement follow ironpython examples
>
> then assign it to DataContext
>
> self.window = System.Windows.Markup.XamlReader.Load(outStream)
> self.window.DataContext = MyViewModel()
>
> this does not seem to work, the property/method in MyViewModel is never
> called nor any data binding happened.
>
> I was able to get ExpandoObject work well though and binding works fine
> self.window.DataContext = System.Dynamic.ExpandoObject()
>
> so, that makes me asking if it makes sense at all to pass a Python class
> object back into .Net framework and expect it works -- even if the proper
> interface is implemented.
>
>
> thanks
>
>
>
>
>
>
>
>
> _________________________________________________
> Python.NET mailing list - [email protected]
> https://mail.python.org/mailman/listinfo/pythondotnet

_________________________________________________
Python.NET mailing list - [email protected]
https://mail.python.org/mailman/listinfo/pythondotnet
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.