This is a migrated thread and some comments may be shown as answers.

VisualTreeHelper is not working

4 Answers 117 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sandro
Top achievements
Rank 1
Sandro asked on 18 Apr 2012, 10:14 AM
Hi

I have this function to get the parent of the control. When I use it on RadGridview, the return is nothing.
Do you have any idea?

Public
Function GetParentObject(Of T As FrameworkElement)(ByVal obj As DependencyObject, Optional ByVal name As String = "") As T
    Dim parent As DependencyObject = VisualTreeHelper.GetParent(obj)
    While parent IsNot Nothing
        If TypeOf parent Is T AndAlso (CType(parent, T).Name = name Or String.IsNullOrEmpty(name)) Then Return CType(parent, T)
        parent = VisualTreeHelper.GetParent(parent)
 
    End While
    Return Nothing
End Function

4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 18 Apr 2012, 11:30 AM
Hello,

I have defined a 'GridView' inside 'Grid' Inside 'MainPage'. When I executed the GetParent() method of the VisualTreeHelper , I got the right parent.

What are the parents of your control? Why do you not use the ParentOfType extension method?

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Sandro
Top achievements
Rank 1
answered on 19 Apr 2012, 08:18 AM
Hi

Here are the parents of the gridview on my control.

UserControl > Grid (LayoutRoot) > Popup > Grid

Do you have code on using ParentOfType extension method if this can solve the problem?


Thank you in advance for the answer.
0
Dimitrina
Telerik team
answered on 19 Apr 2012, 08:23 AM
Hello,

 
The ParentOfType method get the parent element from the visual tree by given type. For example: 

Popup parent = clubsGrid.ParentOfType<Grid>().ParentOfType<Popup>();


Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Sandro
Top achievements
Rank 1
answered on 19 Apr 2012, 08:43 AM
Hi

Thank you for a quick reply.

I already tried your code but still returns nothing.

Many Thanks
Tags
GridView
Asked by
Sandro
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Sandro
Top achievements
Rank 1
Share this question
or