コード例 #1
0
        public static double GetVisibleWidth(FrameworkElement element, UIElement parent)
        {
            if (element == null) throw new ArgumentNullException(nameof(element));
            if (parent == null) throw new ArgumentNullException(nameof(parent));

            var location = element.TransformToAncestor(parent).Transform(new Point(0, 0));

            int width = (int) Math.Floor(element.ActualWidth);
            var hitTest = parent.InputHitTest(new Point(location.X + width, location.Y));

            if (IsAncestorTill(hitTest as FrameworkElement, element, parent))
            {
                return width;
            }

            //BinarySearch here
            int end = (int) Math.Floor(element.ActualWidth);
            int start = 0;

            while (start < end)
            {
                width = (end + start)/2;
                hitTest = parent.InputHitTest(new Point(location.X + width, location.Y));

                if (IsAncestorTill(hitTest as FrameworkElement, element, parent))
                {
                    //Speed tweak
                    hitTest = parent.InputHitTest(new Point(location.X + width + 1, location.Y));

                    if (IsAncestorTill(hitTest as FrameworkElement, element, parent))
                    {
                        start = width;
                    }
                    else
                    {
                        return width;
                    }
                }
                else
                {
                    end = width;
                }
            }


            //for (int width = (int) Math.Floor(element.ActualWidth); width >= 0; width--)
            //{
            //    var hitTest = parent.InputHitTest(new Point(location.X + width, location.Y));
            //
            //    if (hitTest == null) continue;
            //    
            //    if (IsAncestorTill(hitTest as FrameworkElement, element, parent))
            //    {
            //        return width;
            //    }
            //}

            return element.ActualWidth;
        }
コード例 #2
0
ファイル: DragDropTabManager.cs プロジェクト: anaimi/farawla
        private static TabItem FindTabItem(UIElement parent, Point pt)
        {
            var fe = parent.InputHitTest(pt) as FrameworkElement;

            while (fe != null && fe.GetType() != typeof(ExtendedTabItem))
                fe = VisualTreeHelper.GetParent(fe) as FrameworkElement;

            return fe as TabItem;
        }
コード例 #3
0
    public static IDropTarget GetDropTargetAtPoint(
      UIElement draggedElement,
      UIElement dragContainer,
      MouseEventArgs e,
      out Nullable<Point> dropTargetPosition,
      out IDropTarget lastFoundDropTarget )
    {
      dropTargetPosition = null;
      lastFoundDropTarget = null;

      if( dragContainer == null )
        return null;

      IDropTarget dropTarget = null;

      Point pointToDragContainer = e.GetPosition( dragContainer );

      IInputElement hitTest = dragContainer.InputHitTest( pointToDragContainer );

      if( hitTest != null )
      {
        DependencyObject parent = hitTest as DependencyObject;

        while( parent != null )
        {
          dropTarget = parent as IDropTarget;
          if( dropTarget != null )
          {
            lastFoundDropTarget = dropTarget;

            if( dropTarget.CanDropElement( draggedElement ) )
            {
              dropTargetPosition = pointToDragContainer;
              break;
            }
          }
          dropTarget = null;
          parent = Xceed.Utils.Wpf.TreeHelper.GetParent( parent );
        }
      }

      return dropTarget;
    }
    private static IDropTarget GetDropTargetAtPoint( UIElement dragContainer, UIElement draggedElement, Point point )
    {
      IInputElement hitTest = dragContainer.InputHitTest( point );

      if( hitTest == null )
        return null;

      DependencyObject parent = hitTest as DependencyObject;

      while( parent != null )
      {
        IDropTarget dropTarget = parent as IDropTarget;

        ColumnManagerCell cell = dropTarget as ColumnManagerCell;
        bool isCellHitTestible = true;

        if( cell != null )
        {
          // The Cell could be partially or completely under the fixed region of the FixedCellPanel, so not "really" HitTestible
          isCellHitTestible = ColumnReorderingDragSourceManager.TryHitTestCell( cell, point, dragContainer );
        }

        if( ( isCellHitTestible ) && ( dropTarget != null ) && ( dropTarget.CanDropElement( draggedElement ) ) )
        {
          return dropTarget;
        }

        dropTarget = null;
        parent = Xceed.Utils.Wpf.TreeHelper.GetParent( parent );
      }

      return null;
    }
コード例 #5
0
 private IInputElement GetHitTarget(Joint joint, UIElement target)
 {
     Point targetPoint = _layoutRoot.TranslatePoint(GetJointPoint(this.KinectDevice, joint, _layoutRoot.RenderSize, new Point()), target);
     return target.InputHitTest(targetPoint);
 }
コード例 #6
0
 private object GetItemFromPoint(UIElement source, Point point)
 {
     UIElement element = source.InputHitTest(point) as UIElement;
     //if (element != null)
     //{
     //    object data = DependencyProperty.UnsetValue;
     //    while (data == DependencyProperty.UnsetValue)
     //    {
     //        data = source.ItemContainerGenerator.ItemFromContainer(element);
     //        if (data == DependencyProperty.UnsetValue)
     //            element = VisualTreeHelper.GetParent(element) as UIElement;
     //        if (element == source)
     //            return null;
     //    }
     //    if (data != DependencyProperty.UnsetValue)
     //        return data;
     //}
     //return null;
     if (element != null)
     {
         while (element != null)
         {
             element = VisualTreeHelper.GetParent(element) as UIElement;
             if (element is ListBoxItem)
                 return ToDoListBox.ItemContainerGenerator.ItemFromContainer(element);
         }
     }
     return null;
 }
コード例 #7
0
ファイル: MultitouchLogic.cs プロジェクト: zhuangfangwang/ise
		static DependencyObject HitTest(UIElement root, Point position)
		{
			return root.InputHitTest(position) as DependencyObject;
		}
コード例 #8
0
ファイル: MainWindow.xaml.cs プロジェクト: Kazhunter/Kinect
        //GET HIT TARGET!!
        private IInputElement GetHitTarget(Joint joint, UIElement target)
        {
            //GetjoinPoint: get the coordinates of the join within the coordinate space ofthe LayoutRoot
            Point targetPoint = GetJointPoint(this.Kinect, joint,LayoutRoot.RenderSize, new Point());

            //Translates the joint point in the LayoutRoot space to the target space
            targetPoint = LayoutRoot.TranslatePoint(targetPoint, target);

            //If joint in the target returns the UI element in the target's visual tree
            //No-null value = ok
            return target.InputHitTest(targetPoint);
        }
コード例 #9
0
        /// <summary>
        /// Determines whether the given ui element at the given position is occluded by other graph view (for example occluded by scope view).
        /// </summary>
        /// <param name="uiElement">The UI element.</param>
        /// <param name="clickPoint">The click point.</param>
        /// <returns>
        ///   <c>true</c> if this ui element is occluded at the specified position; otherwise, <c>false</c>.
        /// </returns>
        private bool IsUIElementOccludedByAnotherGraphView(UIElement uiElement, Point clickPoint)
        {
            bool isOccluded = true;

            var hitElement = uiElement.InputHitTest(clickPoint) as DependencyObject;
            if (hitElement != null)
            {
                var graphView = hitElement.GetParent<TraceLab.UI.WPF.Views.GraphView>(this);
                if (graphView == this)
                {
                    isOccluded = false;
                }
            }

            return isOccluded;
        }