views:

101

answers:

2

Hello, I (and other programmers from another forum) have been trying to solve a binding problem for a few days. No one could help... Will anyone here be able to help me ? Apparently, the problem seems quite simple but when you dive in it, trust me, you burn some neurons... Here it is : I've created a test project which reproduces the problem. Download it from here. Run the project and :

  • select a member from the listbox

  • type in a ZIP code in the textbox (these are french ZIP, from 01000 to 98000)

  • select a city in the combobox

  • select another member and do the same (with a different ZIP code) then select back the previous member and re-select the other one => see how the member.Ville.ID property is lost and so how the SelectedItem in the combobox is lost as well.

Why the hell does it do that ? How to solve this ?

P.S : sorry for the french in the classes' properties and elsewhere...

+1  A: 

Something is setting that value back. I haven't investigated too much, but I put a binding diagnostic (here's how to do this yourself: here) on your binding and got this:

Update - got raw value '9800'
Update - using final value '9800'
SetValue at level 1 to Ville (hash=15263193) using RuntimePropertyInfo(CodePostal): '9700'
Got PropertyChanged event from Ville (hash=15263193)
Update - got raw value '97001'
Update - using final value '97001'
SetValue at level 1 to Ville (hash=15263193) using RuntimePropertyInfo(CodePostal): '97001'
Got PropertyChanged event from Ville (hash=15263193)
Update - got raw value '01000'
Update - using final value '01000'
SetValue at level 1 to Ville (hash=15263193) using RuntimePropertyInfo(CodePostal): '01000'
Got PropertyChanged event from Ville (hash=15263193)

Notice that as soon as I hit the last "1" in 97001, a PropertyChanged notification was raised resetting it back to 01000, so something was setting it back to that.

I put in a conditional breakpoint in the Set method of your Code for "value.Equals("01000")" and got the stack trace for when that occured:

TestMembre.exe!TestMembre.Ville.set_CodePostal(String value = "01000") Line 47  Basic
TestMembre.exe!TestMembre.Window1.txtCodePostal_TextChanged(Object sender = {System.Windows.Controls.TextBox}, System.Windows.Controls.TextChangedEventArgs e = {System.Windows.Controls.TextChangedEventArgs})

So what you should be noticing here is that the TextChanged event of the txtCodePostal has some code that is setting that value:

Else
   'If the zip code doesn't exist, it is set to one that does
   txtCodePostal.Text = "01000"

I don't know exactly how your logic should work, but that line of code right there is always firing and resetting your value.

Hope this helps!

Anderson Imes
OK. Thanks, I think your message will do help me a lot ! I'll check my code tomorrow... See you
jackprogram
A: 

Your message helped me in the way that I could debug the Binding, thanks to your link. Notice that, for me, the txtCodePostal.Text = "01000" never happened, cause I always type in a right ZIP code. This is meant to happen only if the user type in a ZIP code that doesn't exist. Though, I've used the Trace Sources from Bea Stollnitz web site to debug my binding. I've saved it to this txt file. There are some errors that occur when the SelectionChanged from the listbox happens. I've not understood all stuff yet, but I'm trying... If you could have a look at this file, it'd be pretty kind...

jackprogram