All stackoverflow exceptions should be posted on stackoverflow! On Thursday, March 31, 2016, Hansong Huang <hhsp...@live.com> wrote:
> I am still trying to figure out how to implement WPF MVVM with Python.Net. > Previously, I have successfully used System.Dynamic.ExpandoObject as a > ViewModel container > > self.window = System.Windows.Markup.XamlReader.Load(outStream) > self.window.DataContext = DotNetExpandoObject() > > where DotNetExpandoObject is a wrapper class for > System.Dynamic.ExpandoObject > class DotNetExpandoObject(System.Dynamic.ExpandoObject): > ... in which I redefined __getattr__ and __setattr__ > > it works flawlessly as System.Dynamic.ExpandoObject implements > INotifyPropertyChange interface already > > Now, I would like to get away from using System.Dynamic.ExpandoObject but > to implement my own > > I first tried to expose a python class back to .Net > class MyViewModel(System.Object): > __namespace__ = "WPFPyDemo" > def __init__(self): > super(MyViewModel,self).__init__() > self._inputText = "Line - in" > @clr.clrproperty(str) > def inputText(self): > return self._inputText > @inputText.setter > def inputText(self,value): > self._inputText = value > self.OnPropertyChanged("inputText") > > self.window.DataContext = MyViewModel() > > The one direction data binding works fine, and the "Line - in" text > correctly shows up in the textblock control. > obviously this is not sufficient as there is no INotifyPropertyChange > interface. > > So, I inherit the interface , and tries to implement the typical C# code > " public event PropertyChangedEventHandler PropertyChanged" > > -- not sure how to handle event in Python.Net, the follow code probably is > completely wrong > > class ViewModel(System.ComponentModel.INotifyPropertyChanged): > __namespace__ = "WPFPy" > def __init__(self): > super(ViewModel, self).__init__() > self.PropertyChanged = > System.ComponentModel.PropertyChangedEventHandler > def OnPropertyChanged(self, propertyName): > if self.PropertyChanged != None: > PropertyChanged(self, > System.ComponentModel.PropertyChangedEventArgs(propertyName)) > > class MyViewModel(ViewModel): > __namespace__ = "WPFPyDemo" > def __init__(self): > super(MyViewModel,self).__init__() > self._inputText = "Line - in" > > @clr.clrproperty(str) > def inputText(self): > return self._inputText > @inputText.setter > def inputText(self,value): > self._inputText = value > self.OnPropertyChanged("inputText") > > > The process terminates due to StackOverflowException. > Looks like the error happens when WFP recoganized INotifyPropertyChange > interface and tries to access MyViewModel class via it. >
_________________________________________________ Python.NET mailing list - PythonDotNet@python.org https://mail.python.org/mailman/listinfo/pythondotnet