c# - Is GetTemplateChild Obsolete in .Net 3.5 and what is the difference between FrameWorkTemplate.FindName and ControlTemplate.FindName -


i overrided template of control in resourcedictionary generic.xaml. in added button on wanted add events.

<setter property="template">     <setter.value>         --added button here.     </setter.value> </setter> 

so in loaded event of control did

button  b = (button)mycontrol.template.findname("partname", mycontrol)  //add events on button 

some on internet read can do

public override void onapplytemplate() {     base.onapplytemplate();      uielement editingelement = gettemplatechild("part_editingelement");     if (editingelement != null)      {         //     } } 

when tried doing suggestion gettemplatechild says not use.

enter image description here

so question

  1. why not use gettemplatechild. obsolete? and

  2. what difference between frameworktemplate.findname , controltemplate.findname?

1.

the difference gettemplatechild return null when:

  • no template exists, or
  • the named object exists not dependencyobject (i don't know if possible).

otherwise, code:

this.gettemplatechild(name) 

is literally equivalent code:

this.template.findname(name, this) 

i don't know why marked "do not use". notice note existed on msdn page version 3 , removed version 3.5, don't know if means anything.


2.

did mean frameworkelement? jens said, controltemplate inherits frameworktemplate, , both use frameworktemplate.findname method. frameworktemplate.findname , frameworkelement.findname different. frameworkelement.findname looks inside child elements not template, while frameworktemplate.findname looks @ template's own elements not parent element it's applied to.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -