Can't find the parent of a templated control by type(!) (wpf) Can't find the parent of a templated control by type(!) (wpf) wpf wpf

Can't find the parent of a templated control by type(!) (wpf)


Have you tried simply to get the originalSource's templatedParent ? :

Control originalSource = e.OriginalSource;MyItemControl myItemControl = originalSource.TemplatedParent as MyItemControl;MyHeaderControl myHeaderControl = originalSource.TemplatedParent as MyHeaderControl;if (MyItemControl != null) ....else if (MyHeaderControl != null) ....

(see: http://msdn.microsoft.com/en-gb/library/system.windows.frameworkelement.templatedparent.aspx)


Check out VisualTreeHelper.GetParent, which will let you walk the visual tree where the controls have actually been instantiated through the template.