At.FF.Krems.Config_Gui.MainWindow.GetDataFromListBox C# (CSharp) Method

GetDataFromListBox() private static method

The get data from list box.
private static GetDataFromListBox ( System.Windows.Controls.ListBox source, Point point ) : object
source System.Windows.Controls.ListBox The source.
point System.Windows.Point The point.
return object
        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;
        }