title: WPF Scrollviewer scroll to child element not working
body: <p>Here is what I am trying to do. I have a Scrollviewer and nested inside it are UserControls, nested in other UserControls, inside grids, stackpanels and other containers. When I click a button that adds yet another child somewhere within this hierarchy I would like to scroll to see said child. Code of function below:</p>
  
  <pre><code> public static void ScrollParentNamedScrollViewerDown(DependencyObject child, string strTargetParent, DependencyObject newStartPoint = null)            
      {
          if(child == null) return;
          if(newStartPoint == null) newStartPoint = child;
          ScrollViewer scvPotentialTarget = GetParentOfType&lt;ScrollViewer&gt;(newStartPoint);
          if (scvPotentialTarget == null) return;
          if (scvPotentialTarget.Name != strTargetParent)
          {
              ScrollParentNamedScrollViewerDown(child, strTargetParent, scvPotentialTarget);
          }
          else
          {
              UIElement scrollTarget = child as UIElement;
              if (scrollTarget == null)
                  scvPotentialTarget.ScrollToBottom();
              else{
                  Point pTarget = scrollTarget.TranslatePoint(new Point(0, 0), scvPotentialTarget);                    
                  if (pTarget == null)
                      scvPotentialTarget.ScrollToBottom();
                  else
                      scvPotentialTarget.ScrollToVerticalOffset(pTarget.Y);
              }
          }
  </code></pre>
  
  <p>This function is used like this:</p>
  
  <pre><code>gbSubWindow.Visibility = System.Windows.Visibility.Visible;
  gbSubWindow.Content = uc;
  ScrollParentNamedScrollViewerDown(gbSubWindow, "OmsWindowScrollViewer");
  </code></pre>
  
  <p>where gbSubWindow was a previously empty, hidden expander at the bottom of a nested UserControl</p>
  
  <p>For some reason I am getting ridiculously low values for the vertical offset when I execute the TranslatePoint function - my scrollviewer scrollheight is near 800, and I am adding a child that will show up at the very bottom beneath 2 large child control and I am getting values in 160ish range.</p>
  
  <p>Anyone have any ideas, what is happening here?</p>