title: ScrollViewer notify on RequestBringIntoView
body: <p>I am attempting to get notified when an element is scrolled into view , </p>
  
  <p>As i understand it , ScrollViewer calls BringIntoView on it's child elements and then 
    the child elements raise a RequestBringIntoView event which the ScrollViewer later catches 
    and handles.</p>
  
  <p>This is done by Registering a Class handler for this Event and catching it as it bubbles up </p>
  
  <pre><code>EventManager.RegisterClassHandler(typeof(ScrollViewer), RequestBringIntoViewEvent, new RequestBringIntoViewEventHandler(OnRequestBringIntoView));
  </code></pre>
  
  <p><a href="http://www.dotnetframework.org/default.aspx/DotNET/DotNET/8@0/untmp/WIN_WINDOWS/lh_tools_devdiv_wpf/Windows/wcp/Framework/System/Windows/Controls/ScrollViewer@cs/4/ScrollViewer@cs" rel="nofollow">ScrollViewer Source Code</a>   </p>
  
  <p>What i need is to get notified each time this process takes place , my attempt is to derive from 
    ScrollViewer and Create my own event of type and approach it in one of 2 ways :</p>
  
  <p>1) Add a class handler for that same event with a true at the end for handling Handled events .</p>
  
  <p>2) Creating my own event which handles events of  type RequestBringIntoViewEvent </p>
  
  <pre><code>public class NotifyOnBringIntoViewScrollViewer : ScrollViewer
  {
      static NotifyOnBringIntoViewScrollViewer()
      {
          // for secnario (2) replace RequestBringIntoViewEvent with Noti
          EventManager.RegisterClassHandler(typeof(NotifyOnBringIntoViewScrollViewer),RequestBringIntoViewEvent , new RequestBringIntoViewEventHandler(OnRequestBringIntoView), true);                       
      }
  
  
      public static readonly RoutedEvent NotifyBringIntoViewEvent = EventManager.RegisterRoutedEvent(
                  "NotifyBringIntoView", RoutingStrategy.Direct, typeof(RequestBringIntoViewEventHandler), typeof(NotifyOnBringIntoViewScrollViewer));
  
      private static void OnRequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
      {
          // notify ..
      }
  }
  </code></pre>
  
  <p>The handler is never reached , for one or tow reasons , </p>
  
  <p>1) I miss understood the way routed events works in regard to registering handlers .
  2) My child elements never raise RequestBringIntoView , my attempt for this is as follows :</p>
  
  <p>cs :</p>
  
  <pre><code>   public List&lt;int&gt; Items
      {
          get
          {
              return new List&lt;int&gt;
              {
                  1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25
              };
          }
      }
  </code></pre>
  
  <p>xaml : </p>
  
  <pre><code>  &lt;local:NotifyOnBringIntoViewScrollViewer&gt;
        &lt;ItemsControl ItemsSource="{Binding Items}"&gt;
  
           &lt;ItemsControl.ItemsPanel&gt;
                &lt;ItemsPanelTemplate&gt;
                    &lt;VirtualizingStackPanel /&gt;
                &lt;/ItemsPanelTemplate&gt;
            &lt;/ItemsControl.ItemsPanel&gt;
  
            &lt;ItemsControl.ItemTemplate&gt;
                &lt;DataTemplate&gt;
                    &lt;TextBlock Text="{Binding}"/&gt;
                 &lt;/DataTemplate&gt;
             &lt;/ItemsControl.ItemTemplate&gt;                
         &lt;/ItemsControl&gt;
      &lt;/local:NotifyOnBringIntoViewScrollViewer&gt;
  </code></pre>
  
  <p>FYI : VirtualizingStackPanel  , i put this because i wasn't sure that this is the default panel 
        and if with out Virtualizing BringIntoView is ever called , since they are already in view.</p>