title: Detecting when a template was loaded in wpf
body: <p>I am working with an attached behavior for logging user actions on a ScrollBar.</p>
  
  <p>my code:</p>
  
  <pre><code>class ScrollBarLogBehavior : Behavior&lt;ScrollBar&gt;
  {
      protected override void OnAttached()
      {
          base.OnAttached();
          AssociatedObject.Loaded += new RoutedEventHandler(AssociatedObject_Loaded);
      }
  
      void AssociatedObject_Loaded(object sender, RoutedEventArgs e)
      {
          ...
          var track = (Track)AssociatedObject.Template.FindName("PART_Track", AssociatedObject);
          // ** HERE is the problem: track is null ! **
          ...
      }
  </code></pre>
  
  <p>How can I detect that the template has loaded and I can find the Track?
  (when I call <code>AssociatedObject.Template.LoadContent()</code> the result containt the requested Track, so it i a matter of timing and not a matter of wrong template or naming)</p>