Note that there are some explanatory texts on larger screens.

plurals
  1. PODatabinding updating with outdated values
    primarykey
    data
    text
    <p>I am not understanding the following 4 points about databinding. Not sure if i get unexpected results (outdated data in code behind), or if this is just a result of me misunderstanding how things work.</p> <ol> <li>Bound data to a textbox updates when i leave the textbox. What event EXACTLY does this? LostFocus? </li> <li>When using the now changed data in code behind it seems to still use the OLD data. Why is this happening? Could point 3 be the reason?</li> <li>After the textbox updates i did a test and set datacontext to nothing and reaplied datacontext to the same scource. The values shown are the values before i edited them. Why did they show up after editing, but returned to the old values after rebinding?</li> <li>After changing the values for the second time it seems like code behind uses the data after my first change. Rebinding like in point 3 leads to the same result (value after first change, second change ignored). Seems like code behind is always one update behind, can i change this?</li> </ol> <p>Anyone able to explain why this happens? </p> <p><strong>Desired behavior:</strong></p> <p>I want the people count to update when I edit the housing count. Preferable on the fly, but after losing focus is fine. When losing focus the value for isle ID 0 should be the right one tho, and not the outdated value.</p> <p><strong>For easier understanding</strong>, a picture with 3 screens and related code samples. </p> <p><a href="http://www.mathematik-lehramtsstudium.de/BindingExample.jpg" rel="nofollow">http://www.mathematik-lehramtsstudium.de/BindingExample.jpg</a></p> <p><strong>My class:</strong></p> <pre><code>//class for isles public class isle : INotifyPropertyChanged { //Dummyvariables,... private int _intBauer; private int _intBauerBev; //variables public int intIsleID { set; get; } //isle ID public string strName { set; get; } //isle name public int intBauer //housing count { set { this._intBauer = value; NotifyPropertyChanged("intBauer"); NotifyPropertyChanged("intBauerBev"); } get { return _intBauer; } } public int intBauerBev //each house hosts 8 people { set { this._intBauerBev = value;} get { return intBauer * 8; } } protected void NotifyPropertyChanged(String propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } public event PropertyChangedEventHandler PropertyChanged; } </code></pre> <p><strong>LostFocus-Event for updating the right side oft he page</strong></p> <pre><code> private void textboxHäuser_LostFocus(object sender, RoutedEventArgs e) { //Gesamtzahl neu berechnen listIsles[0].intBauer = 0; for (int i = 1; i &lt; 10; i++) { listIsles[0].intBauer += listIsles[i].intBauer; } //hard refresh DataContext, since it does not seem to update itself //leaving these two lines out of my code changes nothing tho, as expected gridInfoGesamt.DataContext = ""; gridInfoGesamt.DataContext = listIsles[0]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload