public object GetObjectXY(Point _point) { HitTestResult ht = VisualTreeHelper.HitTest(this, _point); string str = "null"; if (ht != null) { var dv = (ht.VisualHit as DrawingVisual); str = dv == null ? "null" : "IDX[" + Visuals.IndexOf(dv) + "] : " + dv.ToString() + " > "; return(dv); } return(null); }
// @debug public String TestHitTest(double x, double y) { //Point HitPoint = e.GetPosition(canvas1); //hitArea = new EllipseGeometry(HitPoint, 1.0, 1.0); ////This line will call a call back method HitTestCallBack //VisualTreeHelper.HitTest(canvas1, null, HitTestCallBack, //new GeometryHitTestParameters(hitArea)); // http://www.c-sharpcorner.com/UploadFile/yougerthen/wpf-and-user-interactivity-part-i-dealing-with-geometries-and-shapes/ //HitTestResult ht = (Visuals[1] as DrawingVisual).HitTest(new Point(x, y)); HitTestResult ht = VisualTreeHelper.HitTest(this, new Point(x, y)); string str = "null"; if (ht != null) { var dv = (ht.VisualHit as DrawingVisual); str = dv == null ? "null" : "IDX[" + Visuals.IndexOf(dv) + "] : " + dv.ToString() + " > "; //String str = ht == null ? "null" : (ht as DrawingVisual).ToString(); //str += (ht as GeometryHitTestResult).IntersectionDetail.ToString(); } return(str); }
/// <summary> /// Inserts an element into a collection at the specified index position. /// </summary> /// <param name="index">The index position where you want to insert the element.</param> /// <param name="element">The element to insert into the collection.</param> public override void Insert(int index, UIElement element) { if (_isItemsHost) { base.Insert(index, element); } else { ValidateElement(element); VerifyWriteAccess(); // Add to the external list _externalChildren.Insert(index, element); // Add to internal logical tree SetLogicalParent(element); // Add to the internal visual tree (in same relative position in the visual collection) if (_internalChildren.Count == 0) { _internalChildren.Add(element); } else if (index == 0) { _internalChildren.Insert(0, element); } else { _internalChildren.Insert(_internalChildren.IndexOf(_externalChildren[index - 1]) + 1, element); } // Instruct the visual parent it must measure with the new child element _visualParent.InvalidateMeasure(); // Added event is always generated after the base call OnUIElementsAdded(new UIElementsEventArgs(element)); } }
/// <summary> /// Attaches a stroke visual to the tree based on the stroke's /// drawing attributes and/or its z-order (index in the collection). /// </summary> private void AttachVisual(StrokeVisual visual, bool buildingStrokeCollection) { System.Diagnostics.Debug.Assert(_strokes != null); if (visual.Stroke.DrawingAttributes.IsHighlighter) { // Find or create a container visual for highlighter strokes of the color ContainerVisual parent = GetContainerVisual(visual.Stroke.DrawingAttributes); Debug.Assert(visual is StrokeVisual); //insert StrokeVisuals under any non-StrokeVisuals used for dynamic inking int i = 0; for (int j = parent.Children.Count - 1; j >= 0; j--) { if (parent.Children[j] is StrokeVisual) { i = j + 1; break; } } parent.Children.Insert(i, visual); } else { // For regular ink we have to respect the z-order of the strokes. // The implementation below is not optimal in a generic case, but the // most simple and should work ok in most common scenarios. // Find the nearest non-highlighter stroke with a lower z-order // and insert the new visual right next to the visual of that stroke. StrokeVisual precedingVisual = null; int i = 0; if (buildingStrokeCollection) { Stroke visualStroke = visual.Stroke; //we're building up a stroke collection, no need to start at IndexOf, i = Math.Min(_visuals.Count, _strokes.Count); //not -1, we're about to decrement while (--i >= 0) { if (object.ReferenceEquals(_strokes[i], visualStroke)) { break; } } } else { i = _strokes.IndexOf(visual.Stroke); } while (--i >= 0) { Stroke stroke = _strokes[i]; if ((stroke.DrawingAttributes.IsHighlighter == false) && (_visuals.TryGetValue(stroke, out precedingVisual) == true) && (VisualTreeHelper.GetParent(precedingVisual) != null)) { VisualCollection children = ((ContainerVisual)(VisualTreeHelper.GetParent(precedingVisual))).Children; int index = children.IndexOf(precedingVisual); children.Insert(index + 1, visual); break; } } // If found no non-highlighter strokes with a lower z-order, insert // the stroke at the very bottom of the regular ink visual tree. if (i < 0) { ContainerVisual parent = GetContainerVisual(visual.Stroke.DrawingAttributes); parent.Children.Insert(0, visual); } } }
public override int IndexOf(UIElement element) { return(visualChildren.IndexOf(element)); }
public int IndexOf(SplitContainer container) { return(collection.IndexOf(container)); }