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


in wpf project have bit complex control. in project use controls (they're templated), besides mainwindow.

on 1 screen have following layout (for showing layout after templates have been applied , contents filled):

myscreencontrol
-mytablecontrol
--itemscontrol
--- headeritemscontrol
-----headeritemscontrol.header
------myheadercontrol
-----headeritemscontrol.items
------myitemcontrol
------myitemcontrol
------myitemcontrol
...

when i'm in screencontrol's code file, in onmouseleftbuttondown method determine if click event came myheadercontrol or myitemcontrol.

the mousebuttoneventargs's source screencontrol , originalsource textblock in myitemcontrol/myheadercontrol 's template.

my first attempt find myitemcontrol/myheadercontrol start originalsource , recursively @ type of parent property. works fine till root of template (which in case viewbox), root has no parent element.

i've used method in az earlier project of mine , worked, working usercontrols, not controls, nor templates.

any ideas how should approach problem (a idea wellcome code)?

thx, tenshiko

have tried originalsource's templatedparent ? :

control originalsource = e.originalsource;  myitemcontrol myitemcontrol = originalsource.templatedparent myitemcontrol; myheadercontrol myheadercontrol = originalsource.templatedparent myheadercontrol;  if (myitemcontrol != null) .... else if (myheadercontrol != null) .... 

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


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -