Property binding is easy to mistake property names. If you mistake property name, you can't bind property correctly but also an application suddenly crashes without any errors.
So, please look at this code attentively. If you write such code, you can pass build action, but your application crashes suddenly without errors.
public class ItemProperties : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public ItemProperties() { } private string m_Text1; public string Text1 { get { return Text1; } set { m_Text1 = value; OnPropertyChanged("Text1"); } } protected void OnPropertyChanged(string name) { PropertyChangedEventHandler handler = this.PropertyChanged; if (handler != null) handler(this, new PropertyChangedEventArgs(name)); } }
The wrong code is here. If you write like this, your application suddenly shutdown.
get { return Text1; }You need to write like this.
get { return m_Text1; }
I don't know why debugger can't catch error, but I noticed we need to pay attention when we use property binding.
I dont see how this has to do with property binding? The Error is an eternal loop on the Get of Text1. But you are right the debugger or compiler should catch this. Maybe only with property binding this error results in a silent crash which are the most annoying crashes.
ReplyDeleteAre you certain that you're not getting a System.StackOverflowException? See Microsoft's official response to this issue here from 2008:
ReplyDeletehttp://stackoverflow.com/questions/2336847/why-doesnt-the-c-sharp-compiler-stop-properties-from-referring-to-themselves
The "Anonymous" user above is correct - this is not called "property binding" - it is "property recursion".
ReplyDelete@Anonymous thanks your comment. We just talked about you said in Twitter. I also hope debugger catch internal stack overflow exception. So, please see my previous blog post the reason why I use property binding.(It's related my WP app)
ReplyDelete@Dan Colasanti Thanks your comment and your twitter reply. Exactly, it's property recursion.I could get a whole sight in this problem. but I never got any errors from debugger.
ReplyDeleteThe Joining Financial Contract can cope with two main areas: residence , resources and servicing.
ReplyDeleteProperty Management Companies
A large number of Arizona home owners will go through the property tax charm process this year because the evaluation section wrongly evaluated their properties value.
ReplyDeleteBusiness for Sale Florida