/// <summary> /// Enumerates all the children for a specified view group. /// </summary> /// <param name="view">The view group to get the children from</param> /// <param name="maxDepth">The depth to stop looking for children.</param> /// <returns>A lazy enumerable of views</returns> public static IEnumerable <_View> EnumerateAllChildren(this _ViewGroup view, int maxDepth = 20) { var children = view.GetChildren().OfType <_ViewGroup>(); foreach (var child in children) { yield return(child); if (maxDepth > 0) { if (child is _ViewGroup childGroup) { foreach (var subResult in childGroup.EnumerateAllChildren(maxDepth - 1)) { yield return(subResult); } } } } }
/// <summary> /// Enumerates all the children for a specified view group. /// </summary> /// <param name="view">The view group to get the children from</param> /// <param name="maxDepth">The depth to stop looking for children.</param> /// <returns>A lazy enumerable of views</returns> public static IEnumerable<_View> EnumerateAllChildren(this _ViewGroup view, int maxDepth = 20) { var children = view.GetChildren().OfType<UIElement>(); foreach (var sub in children) { yield return sub; if (maxDepth > 0) { var childGroup = sub as _ViewGroup; if (childGroup != null) { foreach (var subResult in childGroup.EnumerateAllChildren(maxDepth - 1)) { yield return subResult; } } } } }
/// <summary> /// Enumerates all the children for a specified view group. /// </summary> /// <param name="view">The view group to get the children from</param> /// <param name="selector">The selector function</param> /// <param name="maxDepth">The depth to stop looking for children.</param> /// <returns>A lazy enumerable of views</returns> public static IEnumerable <_View> EnumerateAllChildren(this _ViewGroup view, Func <_View, bool> selector, int maxDepth = 20) { var children = view.GetChildren().OfType <UIElement>(); foreach (var sub in children) { if (selector(sub)) { yield return(sub); } else if (maxDepth > 0) { var childGroup = sub as _ViewGroup; if (childGroup != null) { foreach (var subResult in childGroup.EnumerateAllChildren(selector, maxDepth - 1)) { yield return(subResult); } } } } }
private bool PropagageEventRecursive(PointerEventArgs args, Point root, UIElement element, Action <UIElement> raiseEvent) { bool raised = false; var rect = element.LayoutSlotWithMarginsAndAlignments; rect.X += root.X; rect.Y += root.Y; var position = args.CurrentPoint.Position; if (element.RenderTransform != null) { position = element.RenderTransform.Inverse.TransformPoint(position); } if (position.X >= rect.X && position.Y >= rect.Y && position.X <= rect.X + rect.Width && position.Y <= rect.Y + rect.Height) { foreach (var e in element.GetChildren().ToArray()) { raised |= PropagageEventRecursive(args, rect.Location, e, raiseEvent); } var isHitTestVisible = element.GetValue(HitTestVisibilityProperty) is HitTestVisibility hitTestVisibility && hitTestVisibility == HitTestVisibility.Visible; if (!raised && isHitTestVisible) { if (!element._pointerEntered) { // Console.WriteLine($"PointerManager.Entered [{element}/{element.GetHashCode():X8}"); element._pointerEntered = true; var pointer = new Pointer(args.CurrentPoint.PointerId, PointerDeviceType.Mouse, false, isInRange: true); var pointerArgs = new PointerRoutedEventArgs(args, pointer, element); TraverseAncestors(element, pointerArgs, e => e.OnNativePointerEnter(pointerArgs)); } raiseEvent(element); raised = true; } } else { if (element._pointerEntered) { element._pointerEntered = false; // Console.WriteLine($"PointerManager.Exited [{element}/{element.GetHashCode():X8}"); var pointer = new Pointer(args.CurrentPoint.PointerId, PointerDeviceType.Mouse, false, isInRange: true); var pointerArgs = new PointerRoutedEventArgs(args, pointer, element); TraverseAncestors(element, pointerArgs, e => e.OnNativePointerExited(pointerArgs)); } } return(raised); }
private bool PropagageEventRecursive(PointerEventArgs args, Point root, UIElement element, Matrix3x2 currentTransform, Action <UIElement> raiseEvent) { bool raised = false; var elementRect = element.LayoutSlotWithMarginsAndAlignments; elementRect.X += root.X; elementRect.Y += root.Y; var position = args.CurrentPoint.Position; var pointer = new Pointer(args.CurrentPoint.PointerId, PointerDeviceType.Mouse, false, isInRange: true); var pointerArgs = new PointerRoutedEventArgs(args, element); if (element.RenderTransform != null) { currentTransform *= element.RenderTransform.MatrixCore; elementRect = currentTransform.Transform(elementRect); } if (elementRect.Contains(position)) { foreach (var e in element.GetChildren().Reverse().ToArray()) { if (PropagageEventRecursive(args, elementRect.Location, e, currentTransform, raiseEvent)) { return(true); } } var isHitTestVisible = element.GetValue(HitTestVisibilityProperty) is HitTestVisibility hitTestVisibility && hitTestVisibility == HitTestVisibility.Visible; if (isHitTestVisible) { if (!element.IsOver(pointer)) { element.OnNativePointerEnter(pointerArgs); } raiseEvent(element); return(true); } } else { bool RecursePointerExited(UIElement e) { if (e.IsOver(pointer)) { foreach (var child in e.GetChildren().Reverse().ToArray()) { if (RecursePointerExited(child)) { return(true); } } e.OnNativePointerExited(pointerArgs); return(true); } return(false); } RecursePointerExited(element); } return(raised); }
private static void recursiveResize(UIElement uiElement, TransformGroup transformGroup, double ratio) { foreach (var o in uiElement.GetChildren().Where(c => c is UIElement)) { if (o is Panel) { var panel = (Panel)o; (panel).Margin = new Thickness( panel.Margin.Left / ratio, panel.Margin.Top / ratio, panel.Margin.Right / ratio, panel.Margin.Bottom / ratio); // recursive call. recursiveResize((UIElement)o, transformGroup, ratio); } else if (o is FrameworkElement) { var element = (FrameworkElement)o; element.Margin = new Thickness( element.Margin.Left / ratio, element.Margin.Top / ratio, element.Margin.Right / ratio, element.Margin.Bottom / ratio); element.RenderTransformOrigin = new Point(0.5, 0.5); element.RenderTransform = transformGroup; } } }