예제 #1
0
 private static object GetElementFromPoint(ItemsControl box, Point point)
 {
     var element = (UIElement)box.InputHitTest(point);
     while (true) {
         if (element == box) {
             return null;
         }
         var item = box.ItemContainerGenerator.ItemFromContainer(element);
         var itemFound = !(item.Equals(DependencyProperty.UnsetValue));
         if (itemFound) {
             return item;
         }
         element = (UIElement)VisualTreeHelper.GetParent(element);
     }
 }
예제 #2
0
파일: WPFHelpers.cs 프로젝트: tica/DataFlow
 public static object GetObjectDataFromPoint(ItemsControl 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;
 }
예제 #3
0
        public static object GetDataObjectFromItemsControl(ItemsControl itemsControl, Point p)
        {
            UIElement element = itemsControl.InputHitTest(p) as UIElement;
            while (element != null)
            {
                if (element == itemsControl)
                    return null;

                object data = itemsControl.ItemContainerGenerator.ItemFromContainer(element);
                if (data != DependencyProperty.UnsetValue)
                {
                    return data;
                }
                else
                {
                    element = VisualTreeHelper.GetParent(element) as UIElement;
                }
            }
            return null;
        }
예제 #4
0
        private CollectionViewGroup FindGroup(ItemsControl itemsControl, Point position)
        {
            var element = itemsControl.InputHitTest(position) as DependencyObject;

              if (element != null) {
            var groupItem = element.GetVisualAncestor<GroupItem>();

            if (groupItem != null) {
              return groupItem.Content as CollectionViewGroup;
            }
              }

              return null;
        }
예제 #5
0
 /// <summary>
 /// 获取鼠标位置的元素
 /// </summary>
 /// <param name="itemsControl"></param>
 /// <param name="point"></param>
 /// <returns></returns>
 private object GetElementFromPoint(ItemsControl itemsControl, Point point)
 {
     UIElement element = itemsControl.InputHitTest(point) as UIElement;
     while (element != null)
     {
         if (Equals(element, itemsControl))
             return null;
         object item = itemsControl.ItemContainerGenerator.ItemFromContainer(element);
         if (!item.Equals(DependencyProperty.UnsetValue))
             return item;
         element = (UIElement)VisualTreeHelper.GetParent(element);
     }
     return null;
 }