title: How to avoid recursive triggering of events in WPF?
body: <p>I am having two WPF (from the standard set) widgets A and B. When I change some property of A it should be set on B, when it is change in B it should be set on A.</p>
  
  <p>Now I have this ugly recursion --> I change A, so code changes B, but since B is changed, it changes A, so it changes B... You have the picture.</p>
  
  <p>How to avoid this recursion the most "standard" way? Naive deleting and adding event handlers does not work, and checking if the new value is the same as old value is not applicable here (because of the fluctuation of calculation -- I am not setting the same value to A and B, but transformed).</p>
  
  <h2>Background</h2>
  
  <p>I always try to put minimum info about the problem to avoid confusion. However, this might help</p>
  
  <ul>
  <li>I didn't write those widgets, I just handle the events, that's all</li>
  <li><p>despite the title "recursive triggering", the handlers are called sequentially, so you have the sequence entry-exit-entry-exit-entry-exit, not entry-entry-entry-exit-exit-exit</p>
  
  <p>and the last, probably the least important, but nevertheless </p></li>
  <li>in this particular case I have common handler for A and B</li>
  </ul>
  
  <p>A and B (in this case) are scrollviewers and I try to maintain proportionally the same position for both of them. The project (by Karin Huber) is here:
  <a href="http://www.codeproject.com/KB/WPF/ScrollSynchronization.aspx" rel="noreferrer">http://www.codeproject.com/KB/WPF/ScrollSynchronization.aspx</a></p>
  
  <h3>Event triggering</h3>
  
  <p>The idea of blocking the events is so popular that I added the sequence of triggering the events, here we go:</p>
  
  <ul>
  <li>I change the A</li>
  <li>A handler is called</li>
  <li>I disable handler of A</li>
  <li>I change B (this is stored, but not triggered)</li>
  <li>I enable handler of A</li>
  <li>now the event is get from the queue </li>
  <li>B handler is called</li>
  <li>I disable handler of B</li>
  <li>I change A</li>
  <li>...</li>
  </ul>
  
  <p>As you see, this is futile.</p>