public static IEnumerable <DependencyObject> GetVisualDescendantsAndSelf(this DependencyObject element) { if (element == null) { throw new ArgumentNullException("element"); } return(VisualTreeExtensions.GetVisualDescendantsAndSelfIterator(element)); }
public static IEnumerable <DependencyObject> GetVisualAncestors(this DependencyObject element) { if (element == null) { throw new ArgumentNullException("element"); } return(Enumerable.Skip <DependencyObject>(VisualTreeExtensions.GetVisualAncestorsAndSelfIterator(element), 1)); }
public static IEnumerable <DependencyObject> GetVisualSiblingsAndSelf(this DependencyObject element) { if (element == null) { throw new ArgumentNullException("element"); } DependencyObject parent = VisualTreeHelper.GetParent(element); if (parent != null) { return(VisualTreeExtensions.GetVisualChildren(parent)); } return(Enumerable.Empty <DependencyObject>()); }
private static IEnumerable <DependencyObject> GetVisualDescendantsAndSelfIterator(DependencyObject element) { Queue <DependencyObject> remaining = new Queue <DependencyObject>(); remaining.Enqueue(element); while (remaining.Count > 0) { DependencyObject obj = remaining.Dequeue(); yield return(obj); foreach (DependencyObject dependencyObject in VisualTreeExtensions.GetVisualChildren(obj)) { remaining.Enqueue(dependencyObject); } } }
public static Panel GetItemsHost(this ItemsControl control) { if (control == null) { throw new ArgumentNullException("control"); } DependencyObject reference = control.ItemContainerGenerator.ContainerFromIndex(0); if (reference != null) { return(VisualTreeHelper.GetParent(reference) as Panel); } FrameworkElement parent = Enumerable.FirstOrDefault <DependencyObject>(VisualTreeExtensions.GetVisualChildren((DependencyObject)control)) as FrameworkElement; if (parent != null) { ItemsPresenter itemsPresenter = Enumerable.FirstOrDefault <ItemsPresenter>(Enumerable.OfType <ItemsPresenter>((IEnumerable)VisualTreeExtensions.GetLogicalDescendents(parent))); if (itemsPresenter != null && VisualTreeHelper.GetChildrenCount((DependencyObject)itemsPresenter) > 0) { return(VisualTreeHelper.GetChild((DependencyObject)itemsPresenter, 0) as Panel); } } return((Panel)null); }
public static void ScrollIntoView(this ScrollViewer viewer, FrameworkElement element, double horizontalMargin, double verticalMargin, Duration duration) { if (viewer == null) { throw new ArgumentNullException("viewer"); } if (element == null) { throw new ArgumentNullException("element"); } Rect?boundsRelativeTo = VisualTreeExtensions.GetBoundsRelativeTo(element, (UIElement)viewer); if (!boundsRelativeTo.HasValue) { return; } double verticalOffset = viewer.VerticalOffset; double num1 = 0.0; double viewportHeight = viewer.ViewportHeight; double num2 = boundsRelativeTo.Value.Bottom + verticalMargin; if (viewportHeight < num2) { num1 = num2 - viewportHeight; verticalOffset += num1; } double num3 = boundsRelativeTo.Value.Top - verticalMargin; if (num3 - num1 < 0.0) { verticalOffset -= num1 - num3; } double horizontalOffset = viewer.HorizontalOffset; double num4 = 0.0; double viewportWidth = viewer.ViewportWidth; double num5 = boundsRelativeTo.Value.Right + horizontalMargin; if (viewportWidth < num5) { num4 = num5 - viewportWidth; horizontalOffset += num4; } double num6 = boundsRelativeTo.Value.Left - horizontalMargin; if (num6 - num4 < 0.0) { horizontalOffset -= num4 - num6; } if (duration == (Duration)TimeSpan.Zero) { viewer.ScrollToVerticalOffset(verticalOffset); viewer.ScrollToHorizontalOffset(horizontalOffset); } else { Storyboard storyboard = new Storyboard(); ScrollViewerExtensions.SetVerticalOffset(viewer, viewer.VerticalOffset); ScrollViewerExtensions.SetHorizontalOffset(viewer, viewer.HorizontalOffset); DoubleAnimation doubleAnimation1 = new DoubleAnimation(); doubleAnimation1.To = new double?(verticalOffset); doubleAnimation1.Duration = duration; DoubleAnimation doubleAnimation2 = doubleAnimation1; DoubleAnimation doubleAnimation3 = new DoubleAnimation(); doubleAnimation3.To = new double?(verticalOffset); doubleAnimation3.Duration = duration; DoubleAnimation doubleAnimation4 = doubleAnimation3; Storyboard.SetTarget((DependencyObject)doubleAnimation2, (DependencyObject)viewer); Storyboard.SetTarget((DependencyObject)doubleAnimation4, (DependencyObject)viewer); Storyboard.SetTargetProperty((DependencyObject)doubleAnimation4, new PropertyPath((object)ScrollViewerExtensions.HorizontalOffsetProperty)); Storyboard.SetTargetProperty((DependencyObject)doubleAnimation2, new PropertyPath((object)ScrollViewerExtensions.VerticalOffsetProperty)); storyboard.Children.Add((Timeline)doubleAnimation2); storyboard.Children.Add((Timeline)doubleAnimation4); storyboard.Begin(); } }
public static ScrollViewer GetScrollHost(this ItemsControl control) { if (control == null) { throw new ArgumentNullException("control"); } Panel itemsHost = ItemsControlExtensions.GetItemsHost(control); if (itemsHost == null) { return((ScrollViewer)null); } return(Enumerable.FirstOrDefault <ScrollViewer>(Enumerable.OfType <ScrollViewer>((IEnumerable)Enumerable.Where <DependencyObject>(VisualTreeExtensions.GetVisualAncestors((DependencyObject)itemsHost), (Func <DependencyObject, bool>)(c => c != control))))); }
internal static IEnumerable <FrameworkElement> GetLogicalDescendents(this FrameworkElement parent) { return(FunctionalProgramming.TraverseBreadthFirst <FrameworkElement>(parent, (Func <FrameworkElement, IEnumerable <FrameworkElement> >)(node => VisualTreeExtensions.GetLogicalChildren(node)), (Func <FrameworkElement, bool>)(node => true))); }
internal static IEnumerable <FrameworkElement> GetLogicalChildren(this FrameworkElement parent) { Popup popup = parent as Popup; if (popup != null) { FrameworkElement popupChild = popup.Child as FrameworkElement; if (popupChild != null) { yield return(popupChild); } } ItemsControl itemsControl = parent as ItemsControl; if (itemsControl != null) { foreach (FrameworkElement frameworkElement in Enumerable.OfType <FrameworkElement>((IEnumerable)Enumerable.Select <int, DependencyObject>(Enumerable.Range(0, itemsControl.Items.Count), (Func <int, DependencyObject>)(index => itemsControl.ItemContainerGenerator.ContainerFromIndex(index))))) { yield return(frameworkElement); } } Queue <FrameworkElement> queue = new Queue <FrameworkElement>(Enumerable.OfType <FrameworkElement>((IEnumerable)VisualTreeExtensions.GetVisualChildren((DependencyObject)parent))); while (queue.Count > 0) { FrameworkElement element = queue.Dequeue(); if (element.Parent == parent || element is UserControl) { yield return(element); } else { foreach (FrameworkElement frameworkElement in Enumerable.OfType <FrameworkElement>((IEnumerable)VisualTreeExtensions.GetVisualChildren((DependencyObject)element))) { queue.Enqueue(frameworkElement); } } } }
public static IEnumerable <DependencyObject> GetVisualSiblings(this DependencyObject element) { return(Enumerable.Where <DependencyObject>(VisualTreeExtensions.GetVisualSiblingsAndSelf(element), (Func <DependencyObject, bool>)(p => p != element))); }