本文整理汇总了C#中System.Windows.Controls.ListBoxItem.TransformToAncestor方法的典型用法代码示例。如果您正苦于以下问题:C# ListBoxItem.TransformToAncestor方法的具体用法?C# ListBoxItem.TransformToAncestor怎么用?C# ListBoxItem.TransformToAncestor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ListBoxItem
的用法示例。
在下文中一共展示了ListBoxItem.TransformToAncestor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: container_SelectionChanged
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));
}
}