Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wPF VisualTreeHelper.GetParent returns wrong class?

Tags:

wpf

I have the following XAML defined.

<Popup x:Class="EMS.Controls.Dictionary.MapTip"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
    PopupAnimation="Slide"
     AllowsTransparency="True" Placement="Mouse"       
       x:Name="root"                   
      >

    <Popup.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Resources/Styles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Popup.Resources>
    <Viewbox x:Name="viewBox" IsHitTestVisible="True">
        <Grid Background="Transparent" Name="mainGrid">

        </Grid>
    </Viewbox>
</Popup>

If I walk up the visual tree using VisualTreeHelper.GetParent from "mainGrid", I eventually get System.Windows.Controls.Primitives.PopupRoot, but never get the Popup itself. Anyone with a theory on why this is and what I can do about it? I neeed Popup and not PopupRoot.

TIA.

like image 554
Klaus Nji Avatar asked Sep 25 '10 14:09

Klaus Nji


1 Answers

LogicalTreeHelper is unable to reach the Popup as well the best one could do is try using the Name the "PopupRoot" to compare to GetType().Name.

like image 137
Neeraj Avatar answered Oct 24 '22 20:10

Neeraj