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
19
Source : CheckedChangeZoomExtentsBehaviour.cs
with MIT License
from ABTSoftware
with MIT License
from 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
Source : VisualTreeUtils.cs
with GNU General Public License v3.0
from Acumatica
with GNU General Public License v3.0
from 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
Source : MethodHelpers.cs
with MIT License
from ADeltaX
with MIT License
from 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
Source : MathUtils.cs
with GNU General Public License v3.0
from ahmed605
with GNU General Public License v3.0
from 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
Source : MagicLaboratory.cs
with MIT License
from alaabenfatma
with MIT License
from alaabenfatma
public static void unLinkChild(UIElement child)
{
var parent = VisualTreeHelper.GetParent(child);
var parentAsPanel = parent as Panel;
parentAsPanel?.Children.Remove(child);
}
19
Source : MainWindow.xaml.cs
with GNU General Public License v3.0
from AndrasMumm
with GNU General Public License v3.0
from 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
Source : FrameworkElementExtensions.cs
with GNU General Public License v3.0
from AndreiFedarets
with GNU General Public License v3.0
from 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
Source : GridViewSorting.cs
with GNU General Public License v3.0
from AndreiFedarets
with GNU General Public License v3.0
from 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
Source : FrameworkElementExtensions.cs
with GNU General Public License v3.0
from AndreiFedarets
with GNU General Public License v3.0
from 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
Source : TreeViewItemExtensions.cs
with Apache License 2.0
from anmcgrath
with Apache License 2.0
from 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
Source : TriggersView.xaml.cs
with BSD 3-Clause "New" or "Revised" License
from anoyetta
with BSD 3-Clause "New" or "Revised" License
from anoyetta
private static TreeViewItem VisualUpwardSearch(
DependencyObject source)
{
while (source != null && !(source is TreeViewItem))
{
source = VisualTreeHelper.GetParent(source);
}
return source as TreeViewItem;
}
19
Source : ScreenPositionHelper.cs
with MIT License
from AntonyCorbett
with MIT License
from 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
Source : ComboBoxTemplateSelector.cs
with MIT License
from AntonyCorbett
with MIT License
from 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
Source : TreeView.cs
with GNU General Public License v3.0
from AnyStatus
with GNU General Public License v3.0
from AnyStatus
private static DependencyObject VisualUpwardSearch<T>(DependencyObject source)
{
while (source != null && source.GetType() != typeof(T))
{
source = VisualTreeHelper.GetParent(source);
}
return source;
}
19
Source : TreeViewItemExtension.cs
with GNU General Public License v2.0
from Asixa
with GNU General Public License v2.0
from 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
Source : ProjectWizard.xaml.cs
with MIT License
from aurelia
with MIT License
from 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
Source : AcrylicMenuItem.cs
with MIT License
from awaescher
with MIT License
from 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
Source : TreeViewHelper.cs
with MIT License
from ay2015
with MIT License
from 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
Source : AyTreeView.cs
with MIT License
from ay2015
with MIT License
from ay2015
static DependencyObject VisualUpwardSearch<T>(DependencyObject source)
{
while (source != null && source.GetType() != typeof(T))
source = VisualTreeHelper.GetParent(source);
return source;
}
19
Source : AyTableViewUtils.cs
with MIT License
from ay2015
with MIT License
from 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
Source : TreeViewHelper.cs
with MIT License
from ay2015
with MIT License
from 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
Source : DragInCanvasBehavior.cs
with MIT License
from ay2015
with MIT License
from 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
Source : AyBigPopup.cs
with MIT License
from ay2015
with MIT License
from 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
Source : UIChildFinder.cs
with MIT License
from ay2015
with MIT License
from 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
Source : UIChildFinder.cs
with MIT License
from ay2015
with MIT License
from 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
Source : WpfTreeHelper.cs
with MIT License
from ay2015
with MIT License
from 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
Source : WpfTreeHelper.cs
with MIT License
from ay2015
with MIT License
from 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
Source : FluidMoveBehavior.cs
with MIT License
from ay2015
with MIT License
from 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
Source : WpfTreeHelper.cs
with MIT License
from ay2015
with MIT License
from 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
Source : DependencyObjectHelper.cs
with MIT License
from ay2015
with MIT License
from ay2015
public static IEnumerable<DependencyObject> GetSelfAndAncestors(this DependencyObject dependencyObject)
{
while (dependencyObject != null)
{
yield return dependencyObject;
dependencyObject = VisualTreeHelper.GetParent(dependencyObject);
}
}
19
Source : FluidMoveBehaviorBase.cs
with MIT License
from ay2015
with MIT License
from 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);
}
}
19
Source : FluidMoveBehaviorBase.cs
with MIT License
from ay2015
with MIT License
from 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
Source : WpfHelper.cs
with MIT License
from ay2015
with MIT License
from 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
Source : WpfHelper.cs
with MIT License
from ay2015
with MIT License
from 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
Source : UIHelper.cs
with MIT License
from Azure-Samples
with MIT License
from 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
Source : Explorer.cs
with MIT License
from Bassman2
with MIT License
from 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
Source : DataGridHelper.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from 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
Source : DropDownButton.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from 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
Source : TreeHelper.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from 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
Source : TreeHelper.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from 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
Source : Layout.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from 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
Source : Extensions.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from 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
Source : Layout.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from beckzhu
internal static bool IsContainedWithinBranch(DependencyObject dependencyObject)
{
do
{
dependencyObject = VisualTreeHelper.GetParent(dependencyObject);
if (dependencyObject is Branch)
return true;
} while (dependencyObject != null);
return false;
}
19
Source : HitTestUtilities.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from 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
Source : HitTestUtilities.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from 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
Source : VisualTreeExtensions.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from 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
Source : VisualTreeExtensions.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from 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
Source : VisualTreeExtensions.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from 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
Source : CommonExtended.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from 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
Source : CommonExtended.cs
with Apache License 2.0
from beckzhu
with Apache License 2.0
from 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;
}
See More Examples