.Parent property is Nothing is some cases....

Jan 20, 2009 at 7:39 AM
Hi Guys,

I have a custom class control named CustomDataGrid that inherits from Datagrid.  I have it hosted in a stackpanel as below 

<UserControl x:Class="HostUI"......>
    <StackPanel>
        <StackPanel.Resources> ... </StackPanel.Resources>
        <custom:CustomDataGrid ...>....</CustomDataGrid>
</UserControl>

In run time (during _loaded event of the custom grid  I use Me.Parent) I need to access the parent UI and check if it is "Panel" type and add a toolbar child in it.

But Me.Parent appears as Nothing. Why is this?

Again if I enclose another StackPanel to CustomDataGrid 

<UserControl x:Class="HostUI"......>
    <StackPanel>
        <StackPanel.Resources> ... </StackPanel.Resources>
        <StackPanel>
                <custom:CustomDataGrid ...>....</CustomDataGrid>
        </StackPanel>
</UserControl>

it works fine!

Can some one help me here?

Thx.
Vinit.