static private void container_SelectionChanged(ListBox container, ListBoxItem lbi)
        {
            ScrollViewer sv = container.GetFirstVisualChild<ScrollViewer>();
            if (sv == null)
                return;

            if (sv.ComputedVerticalScrollBarVisibility != Visibility.Visible)
                return;

            ScrollContentPresenter sp = sv.GetFirstVisualChild<ScrollContentPresenter>();

            GeneralTransform childTransform = lbi.TransformToAncestor(sp);//sv
            Rect rectangle = childTransform.TransformBounds(new Rect(new Point(0, 0), lbi.RenderSize));

            //Check if the elements Rect intersects with that of the scrollviewer's
            Rect result = Rect.Intersect(new Rect(new Point(0, 0), sp.RenderSize), rectangle);
            //if result is Empty then the element is not in view
            if (result != rectangle)
            {
                double Heigth = rectangle.Top;
                sv.SmoothToVertical(Heigth + sv.VerticalOffset, TimeSpan.FromSeconds(0.5));
            }

        }