标签:RKE code 宽度 nsf 水平 nta for transform 一半
/// <summary> /// 垂直方向滚动到顶部 /// </summary> /// <param name="element"></param> /// <param name="scrollViewer"></param> public static void ScrollViewToVerticalTop(FrameworkElement element, ScrollViewer scrollViewer) { var scrollViewerOffset = scrollViewer.VerticalOffset; var point = new Point(0, scrollViewerOffset); var tarPos = element.TransformToVisual(scrollViewer).Transform(point); scrollViewer.ScrollToVerticalOffset(tarPos.Y); } /// <summary> /// 水平方向滚动到右侧 /// </summary> /// <param name="element"></param> /// <param name="scrollViewer"></param> public static void ScrollViewToHorizontalRight(FrameworkElement element, ScrollViewer scrollViewer) { var scrollViewerOffset = scrollViewer.HorizontalOffset; var point = new Point(scrollViewerOffset, 0); var tarPos = element.TransformToVisual(scrollViewer).Transform(point); scrollViewer.ScrollToHorizontalOffset(tarPos.X); }
如果需要滚动到中间需要减去容器的一半宽度或者高度
标签:RKE code 宽度 nsf 水平 nta for transform 一半
原文地址:https://www.cnblogs.com/tangchun/p/13130149.html