I use the LogicalTreeHelper.GetParent() method recursively to find the root elements of various other WPF elements. This works fine with just about everything, but for a DataGridColumn it fails, like a DataGridTextColumn . I found out that DataGridColumn not part of a logical tree or visual tree. Can I somehow find the DataGrid that it belongs to (and then get the root from the grid)?
While reading the MSDN documentation, I did not find a suitable solution. Thanks.
My code to find the logical root:
private DependencyObject FindLogicalRoot(DependencyObject obj) { if (obj == null) return null; else { var parent = LogicalTreeHelper.GetParent(obj); return parent != null ? FindLogicalRoot(parent) : obj; } }
source share