Ejemplo n.º 1
0
        IEnumerable <ViewItem> HitTest(ViewItem viewItem, Point hitTestPoint)
        {
            var hitTestResult = viewItem.HitTest(null, null, new PointHitTestParameters(hitTestPoint)).ViewHit;

            return(GetSelfAndChildren(hitTestResult)
                   .Where(x => x.RenderSizeBounds.Contains(viewItem.TransformToView(x).Transform(hitTestPoint))));
        }
        protected override Point GetClickablePointCore()
        {
            if (this._item.Parent == null && this._item != this._item.Root && (this.ModelService != null && this._item.Name != null))
            {
                ModelItem root = this.ModelService.Root;
                if (root != null)
                {
                    ModelItem modelItem = this.ModelService.FromName(root, this._item.Name, StringComparison.OrdinalIgnoreCase);
                    if (modelItem != null)
                    {
                        this._item = modelItem;
                    }
                }
            }
            ViewItem  viewItem     = this.ViewItem;
            UIElement uiElement    = (UIElement)this._view;
            ViewItem  ancestorView = this.ModelService == null || this.ModelService.Root == null ? (ViewItem)null : this.ModelService.Root.View;

            if (uiElement == null || viewItem == (ViewItem)null || PresentationSource.FromVisual((Visual)uiElement) == null)
            {
                return(new Point(0.0, 0.0));
            }
            Rect      selectionFrameBounds = viewItem.SelectionFrameBounds;
            double    width  = selectionFrameBounds.Width;
            double    height = selectionFrameBounds.Height;
            double    num1   = 2.0;
            int       num2   = 0;
            Point     point1 = new Point();
            Transform transformToDesignerView = TransformUtil.GetSelectionFrameTransformToDesignerView(this._item.Context, viewItem);
            Transform transformToParentView   = TransformUtil.GetSelectionFrameTransformToParentView(viewItem, ancestorView);

            while (num1 <= width || num1 <= height)
            {
                int    num3 = 1;
                double x    = width / num1;
                for (; (double)num3 < num1; ++num3)
                {
                    int    num4 = 1;
                    double y    = height / num1;
                    for (; (double)num4 < num1; ++num4)
                    {
                        if (num3 % 2 != 0 || num4 % 2 != 0)
                        {
                            if (++num2 > 1000)
                            {
                                return(new Point());
                            }
                            Point         point2        = transformToDesignerView.Transform(new Point(x, y));
                            HitTestResult hitTestResult = HitTestHelper.HitTest((Visual)uiElement, point2, false, (HitTestFilterCallback)null);
                            if (hitTestResult != null && hitTestResult.VisualHit is DesignerView.OpaqueElement)
                            {
                                Point             point3            = transformToParentView.Transform(new Point(x, y));
                                ViewHitTestResult viewHitTestResult = ancestorView.HitTest((ViewHitTestFilterCallback)null, (ViewHitTestResultCallback)null, (HitTestParameters) new PointHitTestParameters(point3));
                                if (viewHitTestResult != null && viewHitTestResult.ViewHit != (ViewItem)null)
                                {
                                    ViewItem viewHit = viewHitTestResult.ViewHit;
                                    bool     flag1   = false;
                                    if (viewItem != viewHit)
                                    {
                                        flag1 = DesignerItemAutomationPeer.IsPartOfTemplate(viewItem, viewHitTestResult.ViewHit);
                                    }
                                    bool flag2 = false;
                                    if (viewItem.ItemType.IsSubclassOf(typeof(UserControl)))
                                    {
                                        flag2 = viewHitTestResult.ViewHit.IsDescendantOf(viewItem);
                                    }
                                    if (viewItem == viewHitTestResult.ViewHit || flag1 || flag2)
                                    {
                                        return(ancestorView.PointToScreen(point3));
                                    }
                                }
                            }
                        }
                        y += height / num1;
                    }
                    x += width / num1;
                }
                num1 *= 2.0;
            }
            return(point1);
        }
Ejemplo n.º 3
0
 public static ViewHitTestResult HitTest(ViewItem reference, Point point, ViewHitTestFilterCallback filterCallback, ViewHitTestFilterCallback modelCallback)
 {
     return(reference.HitTest(filterCallback, (ViewHitTestResultCallback)null, (HitTestParameters) new PointHitTestParameters(point)));
 }