private static object GetDataFromListBox(ListBox 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;
 }
Example #2
0
		private static object GetObjectDataFromPoint(ListBox source, Point point)
		{
			UIElement element = source.InputHitTest(point) as UIElement;
			if (element != null)
			{
				//get the object from the element
				object data = DependencyProperty.UnsetValue;
				while (data == DependencyProperty.UnsetValue)
				{
					// try to get the object value for the corresponding element
					data = source.ItemContainerGenerator.ItemFromContainer(element);

					//get the parent and we will iterate again
					if (data == DependencyProperty.UnsetValue)
						element = VisualTreeHelper.GetParent(element) as UIElement;

					//if we reach the actual listbox then we must break to avoid an infinite loop
					if (element == source)
						return null;
				}

				//return the data that we fetched only if it is not Unset value, 
				//which would mean that we did not find the data
				if (data != DependencyProperty.UnsetValue)
					return data;
			}

			return null;
		}
 private static object GetObjectDataFromPoint(ListBox source, Point point, out UIElement dataContainer)
 {
     dataContainer = (UIElement) null;
       UIElement uiElement = source.InputHitTest(point) as UIElement;
       if (uiElement != null)
       {
     object obj = DependencyProperty.UnsetValue;
     while (obj == DependencyProperty.UnsetValue && obj != null)
     {
       if (source.ItemContainerGenerator == null)
     return (object) null;
       obj = source.ItemContainerGenerator.ItemFromContainer((DependencyObject) uiElement);
       if (obj == DependencyProperty.UnsetValue || obj == null)
     uiElement = VisualTreeHelper.GetParent((DependencyObject) uiElement) as UIElement;
       if (uiElement == source)
     return (object) null;
     }
     if (obj != DependencyProperty.UnsetValue)
     {
       dataContainer = uiElement;
       return obj;
     }
       }
       return (object) null;
 }
        private Boolean IsLyrics(ListBox source, MouseButtonEventArgs e)
        {
            UIElement element = source.InputHitTest(e.GetPosition(source)) as UIElement;

            while (element != null && element != source)
            {
                if (element is AudioItem.AudioItemLyricsView) return true;

                element = VisualTreeHelper.GetParent(element) as UIElement;
            }

            return false;
        }
        private object getElementFromPoint(ListBox listbox, Point point)
        {
            UIElement element = (UIElement)listbox.InputHitTest(point);

            while (true)
            {
                if (element == listbox) return null;

                object item = listbox.ItemContainerGenerator.ItemFromContainer(element);
                bool itemFound = !(item.Equals(DependencyProperty.UnsetValue));

                if (itemFound) return item;

                element = (UIElement)VisualTreeHelper.GetParent(element);
            }
        }
Example #6
0
        /// <summary>
        ///     The get object data from point.
        /// </summary>
        /// <param name="source">
        ///     The source.
        /// </param>
        /// <param name="point">
        ///     The point.
        /// </param>
        /// <returns>
        ///     The get object data from point.
        /// </returns>
        private static string GetObjectDataFromPoint(ListBox source, Point point)
        {
            var element = source.InputHitTest(point) as UIElement;

            if (element != null)
            {
                // Get the object from the element
                object data = DependencyProperty.UnsetValue;
                while (data == DependencyProperty.UnsetValue)
                {
                    // Try to get the object value for the corresponding element
                    data = source.ItemContainerGenerator.ItemFromContainer(element);

                    // Get the parent and we will iterate again
                    if (data == DependencyProperty.UnsetValue)
                    {
                        element = VisualTreeHelper.GetParent(element) as UIElement;
                    }

                    // If we reach the actual listbox then we must break to avoid an infinite loop
                    if (element == source)
                    {
                        return(null);
                    }
                }

                // Return the data that we fetched only if it is not Unset value,
                // which would mean that we did not find the data
                var entry = data as MessageEntry;

                if (entry != null)
                {
                    return(entry.File);
                }
            }

            return(null);
        }
 ListBoxItem findSelectedItem(ListBox c, System.Windows.Point p)
 {
     Visual findFrom = c.InputHitTest(p) as Visual;
     return findFrom.FindParent<ListBoxItem>() as ListBoxItem;
 }
Example #8
0
        /// <summary>The get data from list box.</summary>
        /// <param name="source">The source.</param>
        /// <param name="point">The point.</param>
        /// <returns>The <see cref="object"/>.</returns>
        private static object GetDataFromListBox(ListBox source, Point point)
        {
            var element = source.InputHitTest(point) as UIElement;
            if (element == null)
            {
                return null;
            }

            var data = DependencyProperty.UnsetValue;
            while (data == DependencyProperty.UnsetValue)
            {
                if (element == null)
                {
                    continue;
                }

                data = source.ItemContainerGenerator.ItemFromContainer(element);

                if (data == DependencyProperty.UnsetValue)
                {
                    element = VisualTreeHelper.GetParent(element) as UIElement;
                }

                if (source.Equals(element))
                {
                    return null;
                }
            }

            return data != DependencyProperty.UnsetValue ? data : null;
        }
Example #9
0
        private Artist GetBoundItemFromPoint(ListBox box, Point point)
        {
            UIElement element = box.InputHitTest(point) as UIElement;
            while (element != null)
            {
                if (element == box)
                {
                    return null;
                }

                Artist item = getDataItem(element);
                bool itemFound = (item != null);
                if (itemFound)
                {
                    return (Artist)item;
                }
                else
                {
                    element = VisualTreeHelper.GetParent(element) as UIElement;
                }
            }
            return null;
        }