MainPage.xaml
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name="GridA">
<Grid x:Name="GridB"/>
</Grid>
</Grid>
It is possible get GridB
parent from GridB
This is what I'm trying to do
//Null
Panel parent1 = GridB.Parent as Panel;
//Null
Panel parent2 = VisualTreeHelper.GetParent(GridB) as Panel;
All of them return null.
Any idea?
Use VisualTreeHelper.GetParent
method but as UIElement
not Panel
like this:
var parent = VisualTreeHelper.GetParent(GridB) as UIElement;
string pName = (parent as Grid).Name; //GridA
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With