System.Windows.Media.VisualTreeHelper.GetParent(System.Windows.DependencyObject)

Here are the examples of the csharp api System.Windows.Media.VisualTreeHelper.GetParent(System.Windows.DependencyObject) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

558 Examples 7

19 View Source File : TreeHelper.cs
License : Apache License 2.0
Project Creator : beckzhu

public static IEnumerable<DependencyObject> GetAncestors(this DependencyObject child)
        {
            var parent = VisualTreeHelper.GetParent(child);
            while (parent != null)
            {
                yield return parent;
                parent = VisualTreeHelper.GetParent(parent);
            }
        }

19 View Source File : VisualTreeExtensions.cs
License : Apache License 2.0
Project Creator : beckzhu

public static DependencyObject GetVisualAncestor(this DependencyObject d, Type itemSearchType, ItemsControl itemsControl,Type itemContainerSearchType)
        {
            if (itemsControl == null) throw new ArgumentNullException(nameof(itemsControl));
            if (itemContainerSearchType == null) throw new ArgumentNullException(nameof(itemContainerSearchType));

            var visualTreeRoot = d.FindVisualTreeRoot();
            var currentVisual = VisualTreeHelper.GetParent(visualTreeRoot);

            while (currentVisual != null && itemSearchType != null)
            {
                var currentVisualType = currentVisual.GetType();
                if (currentVisualType == itemSearchType || currentVisualType.IsSubclreplacedOf(itemSearchType))
                {
                    if (currentVisual is TreeViewItem || itemsControl.ItemContainerGenerator.IndexFromContainer(currentVisual) != -1)
                    {
                        return currentVisual;
                    }
                }
                if (itemContainerSearchType.IsreplacedignableFrom(currentVisualType))
                {
                    // ok, we found an ItemsControl (maybe an empty)
                    return null;
                }
                currentVisual = VisualTreeHelper.GetParent(currentVisual);
            }

            return null;
        }

19 View Source File : AyBigPopup.cs
License : MIT License
Project Creator : ay2015

public void FixMaxWidthAndHeight()
        {
            DependencyObject parent = Child;
            do
            {
                parent = VisualTreeHelper.GetParent(parent);

                if (parent != null && parent.ToString() == "System.Windows.Controls.Primitives.PopupRoot")
                {
                    var element = parent as FrameworkElement;

                    element.Width = ReferUIElement.RenderSize.Width;
                    element.Height = ReferUIElement.RenderSize.Height;

                    break;
                }
            }
            while (parent != null);
            Width = ReferUIElement.RenderSize.Width;
            Height = ReferUIElement.RenderSize.Height;
        }

19 View Source File : UIHelper.cs
License : MIT License
Project Creator : Azure-Samples

public static T FindVisualParent<T>(DependencyObject child)
          where T : DependencyObject
        {
            // get parent item
            DependencyObject parentObject = VisualTreeHelper.GetParent(child);

            // we’ve reached the end of the tree
            if (parentObject == null) return null;

            // check if the parent matches the type we’re looking for
            T parent = parentObject as T;
            if (parent != null)
            {
                return parent;
            }
            else
            {
                // use recursion to proceed with next level
                return FindVisualParent<T>(parentObject);
            }
        }

19 View Source File : WpfTreeHelper.cs
License : MIT License
Project Creator : ay2015

public static T GetParentObject<T>(DependencyObject obj, string name) where T : FrameworkElement
    {
        DependencyObject parent = VisualTreeHelper.GetParent(obj);

        while (parent != null)
        {
            if (parent is T && (((T)parent).Name == name | string.IsNullOrEmpty(name)))
            {
                return (T)parent;
            }

            parent = VisualTreeHelper.GetParent(parent);
        }

        return null;
    }

19 View Source File : AyTreeView.cs
License : MIT License
Project Creator : ay2015

static DependencyObject VisualUpwardSearch<T>(DependencyObject source)
        {
            while (source != null && source.GetType() != typeof(T))
                source = VisualTreeHelper.GetParent(source);

            return source;
        }

19 View Source File : Layout.cs
License : Apache License 2.0
Project Creator : beckzhu

internal static bool IsContainedWithinBranch(DependencyObject dependencyObject)
        {
            do 
            {                
                dependencyObject = VisualTreeHelper.GetParent(dependencyObject);
                if (dependencyObject is Branch)
                    return true;
            } while (dependencyObject != null);
            return false;
        }

19 View Source File : TriggersView.xaml.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : anoyetta

private static TreeViewItem VisualUpwardSearch(
            DependencyObject source)
        {
            while (source != null && !(source is TreeViewItem))
            {
                source = VisualTreeHelper.GetParent(source);
            }

            return source as TreeViewItem;
        }

19 View Source File : CommonExtended.cs
License : Apache License 2.0
Project Creator : beckzhu

public static T GetElementUnderMouse<T>(this UIElement uIElement) where T : UIElement
        {
            UIElement parent = Mouse.DirectlyOver as UIElement;
            while (parent != null)
            {
                var correctlyTyped = parent as T;
                if (correctlyTyped != null)
                {
                    return correctlyTyped;
                }

                parent = VisualTreeHelper.GetParent(parent) as UIElement;
            }
            return null;
        }

19 View Source File : ComboBoxTemplateSelector.cs
License : MIT License
Project Creator : AntonyCorbett

public override DataTemplate? SelectTemplate(object item, DependencyObject container)
        {
            var parent = container;

            // Search up the visual tree, stopping at either a ComboBox or
            // a ComboBoxItem (or null). This will determine which template to use
            while (parent != null && !(parent is ComboBoxItem) && !(parent is ComboBox))
            {
                parent = VisualTreeHelper.GetParent(parent);
            }

            // If you stopped at a ComboBoxItem, you're in the dropdown
            var inDropDown = parent is ComboBoxItem;

            return inDropDown
                ? DropdownItemsTemplate ?? DropdownItemsTemplateSelector?.SelectTemplate(item, container)
                : SelectedItemTemplate ?? SelectedItemTemplateSelector?.SelectTemplate(item, container);
        }

19 View Source File : WpfHelper.cs
License : MIT License
Project Creator : ay2015

internal static T GetVisualAncestor<T>(this DependencyObject d) where T : clreplaced
    {
        DependencyObject item = VisualTreeHelper.GetParent(d);

        while (item != null)
        {
            T itemAsT = item as T;
            if (itemAsT != null) return itemAsT;
            item = VisualTreeHelper.GetParent(item);
        }

        return null;
    }

19 View Source File : WpfTreeHelper.cs
License : MIT License
Project Creator : ay2015

private static DependencyObject GetParent(DependencyObject element, bool recurseIntoPopup)
    {
        if (recurseIntoPopup)
        {
            Popup popup = element as Popup;
            if (popup != null && popup.PlacementTarget != null)
            {
                return popup.PlacementTarget;
            }
        }
        Visual visual = element as Visual;
        DependencyObject dependencyObject = (visual == null) ? null : VisualTreeHelper.GetParent(visual);
        if (dependencyObject == null)
        {
            FrameworkElement frameworkElement = element as FrameworkElement;
            if (frameworkElement != null)
            {
                dependencyObject = frameworkElement.Parent;
                if (dependencyObject == null)
                {
                    dependencyObject = frameworkElement.TemplatedParent;
                }
            }
            else
            {
                FrameworkContentElement frameworkContentElement = element as FrameworkContentElement;
                if (frameworkContentElement != null)
                {
                    dependencyObject = frameworkContentElement.Parent;
                    if (dependencyObject == null)
                    {
                        dependencyObject = frameworkContentElement.TemplatedParent;
                    }
                }
            }
        }
        return dependencyObject;
    }

19 View Source File : AcrylicMenuItem.cs
License : MIT License
Project Creator : awaescher

private void BlurSubMenu()
		{
			var firstSubItem = ItemContainerGenerator.ContainerFromIndex(0);

			if (firstSubItem == null)
				return;

			var container = VisualTreeHelper.GetParent(firstSubItem) as Visual;

			if (container == null)
				return;

			DependencyObject parent = container;
			int borderIndex = 0;

			while (parent != null)
			{
				if (parent is Border b)
				{
					// only put color on the first border (transparent colors will add up otherwise)
					if (borderIndex == 0)
						b.Background = new SolidColorBrush(Color.FromArgb(80, 0, 0, 0));
					else
						b.Background = Brushes.Transparent;

					borderIndex++;
				}

				parent = VisualTreeHelper.GetParent(parent);
			}

			AcrylicHelper.EnableBlur(container);
		}

19 View Source File : DataGridHelper.cs
License : Apache License 2.0
Project Creator : beckzhu

private static void DataGridOnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var dataGrid = (DataGrid)sender;

            var inputHitTest = dataGrid.InputHitTest(e.GetPosition((DataGrid)sender)) as DependencyObject;

            while (inputHitTest != null)
            {
                var dataGridCell = inputHitTest as DataGridCell;
                if (dataGridCell != null && dataGrid.Equals(dataGridCell.TryFindParent<DataGrid>()))
                {
                    if (dataGridCell.IsReadOnly) return;

                    ToggleButton toggleButton;
                    ComboBox comboBox;
                    if (IsDirectHitOnEditComponent(dataGridCell, e, out toggleButton))
                    {
                        dataGrid.CurrentCell = new DataGridCellInfo(dataGridCell);
                        dataGrid.BeginEdit();
                        toggleButton.SetCurrentValue(ToggleButton.IsCheckedProperty, !toggleButton.IsChecked);
                        dataGrid.CommitEdit();
                        e.Handled = true;
                    }
                    else if (IsDirectHitOnEditComponent(dataGridCell, e, out comboBox))
                    {
                        if (_suppressComboAutoDropDown != null) return;

                        dataGrid.CurrentCell = new DataGridCellInfo(dataGridCell);
                        dataGrid.BeginEdit();
                        //check again, as we move to  the edit  template
                        if (IsDirectHitOnEditComponent(dataGridCell, e, out comboBox))
                        {
                            _suppressComboAutoDropDown = dataGrid;
                            comboBox.DropDownClosed += ComboBoxOnDropDownClosed;
                            comboBox.IsDropDownOpen = true;
                        }
                        e.Handled = true;
                    }

                    return;
                }

                inputHitTest = (inputHitTest is Visual || inputHitTest is Visual3D)
                    ? VisualTreeHelper.GetParent(inputHitTest)
                    : null;
            }
        }

19 View Source File : FrameworkElementExtensions.cs
License : GNU General Public License v3.0
Project Creator : AndreiFedarets

private static T FindParentIntenal<T>(this DependencyObject element) where T : clreplaced
        {
            if (element == null)
            {
                return default(T);
            }
            if (element is T)
            {
                return element as T;
            }
            DependencyObject childElement = VisualTreeHelper.GetParent(element) ?? LogicalTreeHelper.GetParent(element);
            return childElement.FindParentIntenal<T>();
        }

19 View Source File : Layout.cs
License : Apache License 2.0
Project Creator : beckzhu

private static object FindLayoutOrBranchOwner(DependencyObject node, out bool isSecondLineageWhenOwnerIsBranch)
        {
            isSecondLineageWhenOwnerIsBranch = false;
            
            var ancestoryStack = new Stack<DependencyObject>();
            do
            {
                ancestoryStack.Push(node);
                node = VisualTreeHelper.GetParent(node);
                if (node is Layout) 
                    return node;
                
                var branch = node as Branch;
                if (branch == null) continue;

                isSecondLineageWhenOwnerIsBranch = ancestoryStack.Contains(branch.SecondContentPresenter);
                return branch;

            } while (node != null);            

            return null;
        }

19 View Source File : TreeViewHelper.cs
License : MIT License
Project Creator : ay2015

public static TreeViewItem GereplacedemFromObject(this TreeView treeView, object obj)
        {
            try
            {
                DependencyObject dObject = GetContainerFormObject(treeView, obj);
                TreeViewItem tvi = dObject as TreeViewItem;
                while (tvi == null)
                {
                    dObject = VisualTreeHelper.GetParent(dObject);
                    tvi = dObject as TreeViewItem;
                }
                return tvi;
            }
            catch { }
            return null;
        }

19 View Source File : HitTestUtilities.cs
License : Apache License 2.0
Project Creator : beckzhu

public static bool IsNotPartOfSender(object sender, MouseButtonEventArgs e)
        {
            var visual = e.OriginalSource as Visual;
            if (visual == null)
            {
                return false;
            }
            var hit = VisualTreeHelper.HitTest(visual, e.GetPosition((IInputElement)visual));

            if (hit == null)
            {
                return false;
            }
            else
            {
                var depObj = e.OriginalSource as DependencyObject;
                if (depObj == null)
                {
                    return false;
                }
                if (depObj == sender)
                {
                    return false;
                }

                var item = VisualTreeHelper.GetParent(depObj.FindVisualTreeRoot());
                //var item = VisualTreeHelper.GetParent(e.OriginalSource as DependencyObject);

                while (item != null && item != sender)
                {
                    item = VisualTreeHelper.GetParent(item);
                }
                return item != sender;
            }
        }

19 View Source File : MagicLaboratory.cs
License : MIT License
Project Creator : alaabenfatma

public static void unLinkChild(UIElement child)
        {
            var parent = VisualTreeHelper.GetParent(child);
            var parentAsPanel = parent as Panel;
            parentAsPanel?.Children.Remove(child);
        }

19 View Source File : CommonExtended.cs
License : Apache License 2.0
Project Creator : beckzhu

public static T GetElementFromPoint<T>(this ItemsControl itemsControl, Point point) where T : clreplaced
        {
            UIElement element = itemsControl.InputHitTest(point) as UIElement;
            while (element != null)
            {
                if (element == itemsControl)
                    return default(T);
                object item = itemsControl.ItemContainerGenerator.ItemFromContainer(element);
                if (!item.Equals(DependencyProperty.UnsetValue))
                    return item as T;
                if (element is T)
                {
                    return element as T;
                }
                element = (UIElement)VisualTreeHelper.GetParent(element);
            }
            return default(T);
        }

19 View Source File : UIChildFinder.cs
License : MIT License
Project Creator : ay2015

public static DependencyObject GetVisualAncestor(this DependencyObject d, Type type)
    {
        DependencyObject item = VisualTreeHelper.GetParent(d);

        while (item != null)
        {
            if (item.GetType() == type) return item;
            item = VisualTreeHelper.GetParent(item);
        }

        return null;
    }

19 View Source File : WpfTreeHelper.cs
License : MIT License
Project Creator : ay2015

public static T FindParentControl<T>(DependencyObject outerDepObj) where T : DependencyObject
    {
        if (outerDepObj == null) return null;
        DependencyObject dObj = VisualTreeHelper.GetParent(outerDepObj);
        if (dObj == null)
            return null;

        if (dObj is T)
            return dObj as T;

        while ((dObj = VisualTreeHelper.GetParent(dObj)) != null)
        {
            if (dObj is T)
                return dObj as T;
        }

        return null;
    }

19 View Source File : MainWindow.xaml.cs
License : GNU General Public License v3.0
Project Creator : AndrasMumm

private static T FindAnchestor<T>(DependencyObject current)
            where T : DependencyObject
        {
            do
            {
                if (current is T)
                {
                    return (T)current;
                }
                current = VisualTreeHelper.GetParent(current);
            }
            while (current != null);
            return null;
        }

19 View Source File : FluidMoveBehavior.cs
License : MIT License
Project Creator : ay2015

internal override void UpdateLayoutTransitionCore(FrameworkElement child, FrameworkElement root, object tag, TagData newTagData)
		{
			bool flag = false;
			bool flag2 = false;
			object initialIdenreplacedyTag = GetInitialIdenreplacedyTag(child);
			TagData value;
			bool flag3 = FluidMoveBehaviorBase.TagDictionary.TryGetValue(tag, out value);
			if (flag3 && value.InitialTag != initialIdenreplacedyTag)
			{
				flag3 = false;
				FluidMoveBehaviorBase.TagDictionary.Remove(tag);
			}
			Rect rect;
			if (!flag3)
			{
				TagData value2;
				if (initialIdenreplacedyTag != null && FluidMoveBehaviorBase.TagDictionary.TryGetValue(initialIdenreplacedyTag, out value2))
				{
					rect = FluidMoveBehaviorBase.TranslateRect(value2.AppRect, root, newTagData.Parent);
					flag = true;
					flag2 = true;
				}
				else
				{
					rect = Rect.Empty;
				}
				TagData tagData = new TagData();
				tagData.ParentRect = Rect.Empty;
				tagData.AppRect = Rect.Empty;
				tagData.Parent = newTagData.Parent;
				tagData.Child = child;
				tagData.Timestamp = DateTime.Now;
				tagData.InitialTag = initialIdenreplacedyTag;
				value = tagData;
				FluidMoveBehaviorBase.TagDictionary.Add(tag, value);
			}
			else if (value.Parent != VisualTreeHelper.GetParent(child))
			{
				rect = FluidMoveBehaviorBase.TranslateRect(value.AppRect, root, newTagData.Parent);
				flag = true;
			}
			else
			{
				rect = value.ParentRect;
			}
			if ((!IsEmptyRect(rect) && !IsEmptyRect(newTagData.ParentRect) && (!IsClose(rect.Left, newTagData.ParentRect.Left) || !IsClose(rect.Top, newTagData.ParentRect.Top))) || (child != value.Child && TransitionStoryboardDictionary.ContainsKey(tag)))
			{
				Rect currentRect = rect;
				bool flag4 = false;
				Storyboard value3 = null;
				if (TransitionStoryboardDictionary.TryGetValue(tag, out value3))
				{
					object overlay2 = GetOverlay(value.Child);
					AdornerContainer adornerContainer = (AdornerContainer)overlay2;
					flag4 = (overlay2 != null);
					FrameworkElement child2 = value.Child;
					if (overlay2 != null)
					{
						Canvas canvas = adornerContainer.Child as Canvas;
						if (canvas != null)
						{
							child2 = (canvas.Children[0] as FrameworkElement);
						}
					}
					if (!flag2)
					{
						Transform transform = GetTransform(child2);
						currentRect = transform.TransformBounds(currentRect);
					}
					TransitionStoryboardDictionary.Remove(tag);
					value3.Stop();
					value3 = null;
					RemoveTransform(child2);
					if (overlay2 != null)
					{
						AdornerLayer.GetAdornerLayer(root).Remove(adornerContainer);
						TransferLocalValue(value.Child, CacheDuringOverlayProperty, UIElement.RenderTransformProperty);
						SetOverlay(value.Child, null);
					}
				}
				object overlay = null;
				if (flag4 || (flag && FloatAbove))
				{
					Canvas canvas2 = new Canvas();
					canvas2.Width = newTagData.ParentRect.Width;
					canvas2.Height = newTagData.ParentRect.Height;
					canvas2.IreplacedTestVisible = false;
					Canvas canvas3 = canvas2;
					Rectangle rectangle = new Rectangle();
					rectangle.Width = newTagData.ParentRect.Width;
					rectangle.Height = newTagData.ParentRect.Height;
					rectangle.IreplacedTestVisible = false;
					Rectangle rectangle2 = rectangle;
					rectangle2.Fill = new VisualBrush(child);
					canvas3.Children.Add(rectangle2);
					AdornerContainer adornerContainer2 = new AdornerContainer(child);
					adornerContainer2.Child = canvas3;
					AdornerContainer adorner = (AdornerContainer)(overlay = adornerContainer2);
					SetOverlay(child, overlay);
					AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(root);
					adornerLayer.Add(adorner);
					TransferLocalValue(child, UIElement.RenderTransformProperty, CacheDuringOverlayProperty);
					child.RenderTransform = new TranslateTransform(-10000.0, -10000.0);
					canvas3.RenderTransform = new TranslateTransform(10000.0, 10000.0);
					child = rectangle2;
				}
				Rect layoutRect = newTagData.ParentRect;
				Storyboard transitionStoryboard = CreateTransitionStoryboard(child, flag2, ref layoutRect, ref currentRect);
				TransitionStoryboardDictionary.Add(tag, transitionStoryboard);
				transitionStoryboard.Completed += delegate
				{
					Storyboard value4;
					if (TransitionStoryboardDictionary.TryGetValue(tag, out value4) && value4 == transitionStoryboard)
					{
						TransitionStoryboardDictionary.Remove(tag);
						transitionStoryboard.Stop();
						RemoveTransform(child);
						child.InvalidateMeasure();
						if (overlay != null)
						{
							AdornerLayer.GetAdornerLayer(root).Remove((AdornerContainer)overlay);
							TransferLocalValue(child, CacheDuringOverlayProperty, UIElement.RenderTransformProperty);
							SetOverlay(child, null);
						}
					}
				};
				transitionStoryboard.Begin();
			}
			value.ParentRect = newTagData.ParentRect;
			value.AppRect = newTagData.AppRect;
			value.Parent = newTagData.Parent;
			value.Child = newTagData.Child;
			value.Timestamp = newTagData.Timestamp;
		}

19 View Source File : TreeView.cs
License : GNU General Public License v3.0
Project Creator : AnyStatus

private static DependencyObject VisualUpwardSearch<T>(DependencyObject source)
        {
            while (source != null && source.GetType() != typeof(T))
            {
                source = VisualTreeHelper.GetParent(source);
            }

            return source;
        }

19 View Source File : FluidMoveBehaviorBase.cs
License : MIT License
Project Creator : ay2015

private static FrameworkElement GetVisualRoot(FrameworkElement child)
		{
			while (true)
			{
				FrameworkElement frameworkElement = VisualTreeHelper.GetParent(child) as FrameworkElement;
				if (frameworkElement == null)
				{
					return child;
				}
				if (AdornerLayer.GetAdornerLayer(frameworkElement) == null)
				{
					break;
				}
				child = frameworkElement;
			}
			return child;
		}

19 View Source File : DependencyObjectHelper.cs
License : MIT License
Project Creator : ay2015

public static IEnumerable<DependencyObject> GetSelfAndAncestors(this DependencyObject dependencyObject)
		{
			while (dependencyObject != null)
			{
				yield return dependencyObject;
				dependencyObject = VisualTreeHelper.GetParent(dependencyObject);
			}
		}

19 View Source File : ProjectWizard.xaml.cs
License : MIT License
Project Creator : aurelia

private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
        {

            TAncestor FindAncestor<TAncestor>(UIElement uiElement) where TAncestor : clreplaced
            {
                while ((uiElement != null) && !(uiElement is TAncestor))
                    uiElement = VisualTreeHelper.GetParent(uiElement) as UIElement;

                return uiElement as TAncestor;
            }

            var treeViewItem = FindAncestor<TreeViewItem>(sender as UIElement);
            treeViewItem.IsSelected = true;

        }

19 View Source File : WpfHelper.cs
License : MIT License
Project Creator : ay2015

internal static DependencyObject GetVisualAncestor(this DependencyObject d, Type type)
    {
        DependencyObject item = VisualTreeHelper.GetParent(d);

        while (item != null)
        {
            if (item.GetType() == type) return item;
            item = VisualTreeHelper.GetParent(item);
        }

        return null;
    }

19 View Source File : GridViewSorting.cs
License : GNU General Public License v3.0
Project Creator : AndreiFedarets

private static T GetAncestor<T>(DependencyObject reference) where T : DependencyObject
        {
            DependencyObject parent = VisualTreeHelper.GetParent(reference);
            while (!(parent is T))
            {
                parent = VisualTreeHelper.GetParent(parent);
            }
            return (T) parent;
        }

19 View Source File : Explorer.cs
License : MIT License
Project Creator : Bassman2

private static T FindVisualParent<T>(object obj) where T : DependencyObject
        {
            DependencyObject dep = (DependencyObject)obj;
            do
            {
                dep = VisualTreeHelper.GetParent(dep);
            } while (dep != null && dep.GetType() != typeof(T));
            return (T)dep;
        }

19 View Source File : TreeViewHelper.cs
License : MIT License
Project Creator : ay2015

public static TreeViewItem GetParenreplacedem(this TreeViewItem item)
        {
            var dObject = VisualTreeHelper.GetParent(item);
            TreeViewItem tvi = dObject as TreeViewItem;
            while (tvi == null)
            {
                dObject = VisualTreeHelper.GetParent(dObject);
                tvi = dObject as TreeViewItem;
            }
            return tvi;
        }

19 View Source File : DropDownButton.cs
License : Apache License 2.0
Project Creator : beckzhu

private void TryRemoveVisualFromOldTree(object newItem)
        {
            var visual = newItem as Visual;
            if (visual != null)
            {
                var fe = LogicalTreeHelper.GetParent(visual) as FrameworkElement ?? VisualTreeHelper.GetParent(visual) as FrameworkElement;
                if (Equals(this, fe))
                {
                    this.RemoveLogicalChild(visual);
                    this.RemoveVisualChild(visual);
                }
            }
        }

19 View Source File : MathUtils.cs
License : GNU General Public License v3.0
Project Creator : ahmed605

private static Matrix3D GetWorldTransformationMatrix(DependencyObject visual, out Viewport3DVisual viewport)
        {
            Matrix3D worldTransform = Matrix3D.Idenreplacedy;
            viewport = null;

            if (!(visual is Visual3D))
            {
                throw new ArgumentException("Must be of type Visual3D.", "visual");
            }

            while (visual != null)
            {
                if (!(visual is ModelVisual3D))
                {
                    break;
                }

                Transform3D transform = (Transform3D)visual.GetValue(ModelVisual3D.TransformProperty);

                if (transform != null)
                {
                    worldTransform.Append(transform.Value);
                }

                visual = VisualTreeHelper.GetParent(visual);
            }

            viewport = visual as Viewport3DVisual;

            if (viewport == null)
            {
                if (visual != null)
                {
                    // In WPF 3D v1 the only possible configuration is a chain of
                    // ModelVisual3Ds leading up to a Viewport3DVisual.

                    throw new ApplicationException(
                        String.Format("Unsupported type: '{0}'.  Expected tree of ModelVisual3Ds leading up to a Viewport3DVisual.",
                                      visual.GetType().FullName));
                }

                return ZeroMatrix;
            }

            return worldTransform;
        }

19 View Source File : TreeHelper.cs
License : Apache License 2.0
Project Creator : beckzhu

public static DependencyObject GetParentObject(this DependencyObject child)
        {
            if (child == null) return null;

            // handle content elements separately
            var contentElement = child as ContentElement;
            if (contentElement != null)
            {
                DependencyObject parent = ContentOperations.GetParent(contentElement);
                if (parent != null) return parent;

                var fce = contentElement as FrameworkContentElement;
                return fce != null ? fce.Parent : null;
            }

            var childParent = VisualTreeHelper.GetParent(child);
            if (childParent != null)
            {
                return childParent;
            }

            // also try searching for parent in framework elements (such as DockPanel, etc)
            var frameworkElement = child as FrameworkElement;
            if (frameworkElement != null)
            {
                DependencyObject parent = frameworkElement.Parent;
                if (parent != null) return parent;
            }

            return null;
        }

19 View Source File : AyTableViewUtils.cs
License : MIT License
Project Creator : ay2015

public static T GetAncestorByType<T>(DependencyObject element) where T : clreplaced
        {
            if (element == null)
                return default(T);

            if (element as T != null)
                return element as T;

            return GetAncestorByType<T>(VisualTreeHelper.GetParent(element));
        }

19 View Source File : Extensions.cs
License : Apache License 2.0
Project Creator : beckzhu

public static IEnumerable<DependencyObject> VisualTreeAncestory(this DependencyObject dependencyObject)
        {
            if (dependencyObject == null) throw new ArgumentNullException("dependencyObject");

            while (dependencyObject != null)
            {
                yield return dependencyObject;
                dependencyObject = VisualTreeHelper.GetParent(dependencyObject);
            }            
        }

19 View Source File : TreeViewItemExtensions.cs
License : Apache License 2.0
Project Creator : anmcgrath

private static TreeViewItem GetParent(TreeViewItem item)
        {
            var parent = VisualTreeHelper.GetParent(item);
				
            while (!(parent is TreeViewItem || parent is TreeView))
            {
				if (parent == null) return null;
                parent = VisualTreeHelper.GetParent(parent);
            }
            return parent as TreeViewItem;
        }

19 View Source File : HitTestUtilities.cs
License : Apache License 2.0
Project Creator : beckzhu

public static bool IsNotPartOfSender(object sender, MouseButtonEventArgs e)
        {
            var visual = e.OriginalSource as Visual;
            if (visual == null)
            {
                return false;
            }
            var hit = VisualTreeHelper.HitTest(visual, e.GetPosition((IInputElement)visual));

            if (hit == null)
            {
                return false;
            }
            else
            {
                var depObj = e.OriginalSource as DependencyObject;
                if (depObj == null)
                {
                    return false;
                }
                if (depObj == sender)
                {
                    return false;
                }

                var item = VisualTreeHelper.GetParent(depObj.FindVisualTreeRoot());
                //var item = VisualTreeHelper.GetParent(e.OriginalSource as DependencyObject);

                while (item != null && item != sender)
                {
                    item = VisualTreeHelper.GetParent(item);
                }
                return item != sender;
            }
        }

19 View Source File : DragInCanvasBehavior.cs
License : MIT License
Project Creator : ay2015

void replacedociatedObject_MouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            //获得canvas
            if (canvas == null)
            {
                canvas = (Canvas)VisualTreeHelper.GetParent(this.replacedociatedObject);
                //canvas.SizeChanged += canvas_SizeChanged;
            }
            isDragging = true;
            mouseOffset = e.GetPosition(this.replacedociatedObject);
            tempHeight = (double)this.replacedociatedObject.GetValue(FrameworkElement.HeightProperty);
            tempWidth = (double)this.replacedociatedObject.GetValue(FrameworkElement.WidthProperty);
            this.replacedociatedObject.CaptureMouse();
        }

19 View Source File : VisualTreeExtensions.cs
License : Apache License 2.0
Project Creator : beckzhu

public static T GetVisualAncestor<T>(this DependencyObject d)
            where T : clreplaced
        {
            var item = VisualTreeHelper.GetParent(d.FindVisualTreeRoot());

            while (item != null)
            {
                var itemAsT = item as T;
                if (itemAsT != null)
                {
                    return itemAsT;
                }
                item = VisualTreeHelper.GetParent(item);
            }

            return null;
        }

19 View Source File : VisualTreeUtils.cs
License : GNU General Public License v3.0
Project Creator : Acumatica

public static IEnumerable<FrameworkElement> GetVisualAncestors(this FrameworkElement uiElement)
		{
			uiElement.ThrowOnNull(nameof(uiElement));

			return GetVisualAncestorsImpl();

			//-------------------------------------------Local function-----------------------------------
			IEnumerable<FrameworkElement> GetVisualAncestorsImpl()
			{
				FrameworkElement currentAncestor = VisualTreeHelper.GetParent(uiElement) as FrameworkElement;

				while (currentAncestor != null)
				{
					yield return currentAncestor;
					currentAncestor = VisualTreeHelper.GetParent(currentAncestor) as FrameworkElement;
				}		
			}
		}

19 View Source File : VisualTreeExtensions.cs
License : Apache License 2.0
Project Creator : beckzhu

public static DependencyObject GetVisualAncestor(this DependencyObject d, Type itemSearchType, ItemsControl itemsControl)
        {
            if (itemsControl == null) throw new ArgumentNullException(nameof(itemsControl));

            var visualTreeRoot = d.FindVisualTreeRoot();
            var currentVisual = VisualTreeHelper.GetParent(visualTreeRoot);
            DependencyObject lastFoundItemByType = null;

            while (currentVisual != null && itemSearchType != null)
            {
                if (currentVisual == itemsControl)
                {
                    return lastFoundItemByType;
                }
                var currentVisualType = currentVisual.GetType();
                if ((currentVisualType == itemSearchType || currentVisualType.IsSubclreplacedOf(itemSearchType))
                    && (itemsControl.ItemContainerGenerator.IndexFromContainer(currentVisual) != -1))
                {
                    lastFoundItemByType = currentVisual;
                }
                currentVisual = VisualTreeHelper.GetParent(currentVisual);
            }

            return lastFoundItemByType;
        }

19 View Source File : UIChildFinder.cs
License : MIT License
Project Creator : ay2015

public static T GetVisualAncestor<T>(this DependencyObject d) where T : clreplaced
    {
        DependencyObject item = VisualTreeHelper.GetParent(d);

        while (item != null)
        {
            T itemAsT = item as T;
            if (itemAsT != null) return itemAsT;
            item = VisualTreeHelper.GetParent(item);
        }

        return null;
    }

19 View Source File : ScreenPositionHelper.cs
License : MIT License
Project Creator : AntonyCorbett

private static Window? GetParentWindow(DependencyObject child)
        {
            var parentObject = VisualTreeHelper.GetParent(child);

            if (parentObject == null)
            {
                return null;
            }

            if (parentObject is Window parent)
            {
                return parent;
            }

            return GetParentWindow(parentObject);
        }

19 View Source File : CheckedChangeZoomExtentsBehaviour.cs
License : MIT License
Project Creator : ABTSoftware

private static T FindVisualParent<T>(this DependencyObject dependencyObject)
            where T : DependencyObject
        {
            var parent = VisualTreeHelper.GetParent(dependencyObject);
 
            if (parent == null) return null;
 
            var parentT = parent as T;
            return parentT ?? FindVisualParent<T>(parent);
        }

19 View Source File : MethodHelpers.cs
License : MIT License
Project Creator : ADeltaX

public static T VisualUpwardSearch<T>(this DependencyObject source) where T : clreplaced
        {
            while (source != null && !(source is T))
                source = VisualTreeHelper.GetParent(source);

            return source as T;
        }

19 View Source File : FrameworkElementExtensions.cs
License : GNU General Public License v3.0
Project Creator : AndreiFedarets

public static T FindParent<T>(this DependencyObject element) where T : clreplaced
        {
            if (element == null)
            {
                return default(T);
            }
            DependencyObject childElement = VisualTreeHelper.GetParent(element) ?? LogicalTreeHelper.GetParent(element);
            return childElement.FindParentIntenal<T>();
        }

19 View Source File : TreeViewItemExtension.cs
License : GNU General Public License v2.0
Project Creator : Asixa

public static TreeViewItem GetParent(this TreeViewItem item)
        {
            var parent  = VisualTreeHelper.GetParent(item);
            while (!(parent is TreeViewItem || parent is TreeView))
            {
                if (parent == null) return null;
                parent = VisualTreeHelper.GetParent(parent);
            }

            return parent as TreeViewItem;
        }

19 View Source File : FluidMoveBehaviorBase.cs
License : MIT License
Project Creator : ay2015

private void UpdateLayoutTransition(FrameworkElement child)
		{
			if ((child.Visibility != Visibility.Collapsed && child.IsLoaded) || !ShouldSkipInitialLayout)
			{
				FrameworkElement visualRoot = GetVisualRoot(child);
				TagData tagData = new TagData();
				tagData.Parent = (VisualTreeHelper.GetParent(child) as FrameworkElement);
				tagData.ParentRect = ExtendedVisualStateManager.GetLayoutRect(child);
				tagData.Child = child;
				tagData.Timestamp = DateTime.Now;
				try
				{
					tagData.AppRect = TranslateRect(tagData.ParentRect, tagData.Parent, visualRoot);
				}
				catch (ArgumentException)
				{
					if (ShouldSkipInitialLayout)
					{
						return;
					}
				}
				EnsureTags(child);
				object obj = GetIdenreplacedyTag(child);
				if (obj == null)
				{
					obj = child;
				}
				UpdateLayoutTransitionCore(child, visualRoot, obj, tagData);
			}
		}

See More Examples