wpf - Property similar to Label.Target for a custom templated control -


i have control template contains generic contentpresenter. contentpresenter contain accesstext (possibly amongst other things), accesskey should focus whole control. how do that?

here specific simplified example case. (i know implemented in several other ways (e.g. usercontrol), need way various reasons). made up, there minor omissions; point show idea.

imagine want add header textbox. subclass textboxex , add 2 dependency properties header , headertemplate, headeredcontentcontrol. (code trivial , omitted).

then assign template textboxex along these lines:

<controltemplate targettype="textboxex">   <stackpanel>     <contentpresenter name="part_header"       content="{templatebinding header}"       contenttemplate="{templatebinding headertemplate}"       recognizesaccesskey="true" />     <textbox ... /> <!--or other components similar functionality-->   </stackpanel> </controltemplate> 

when using control, might this:

<textboxex template="{staticresource templateabove}" header="_test">   <textboxex.headertemplate>     <datatemplate>       <accesstext text="{binding}" fontsize="14" />     </datatemplate>   </textboxex.headertemplate> </textboxex> 

(of course, in reality done via styles , more elaborate, tried conflate minimal code).

now, renders fine. problem when press alt+t, nothing happens. (except underlining t). want control focus - usual action onaccesskey.

typicaly, such things done using label, has target property, can point control focused. here @ controltemplate level, don't know header template user use; may not have accesstext-related @ all, , don't want restrict in way. yet if such control used, want access key work. supposedly, contentpresenter.recognizesaccesskey should help, how tell do, i.e. (sub-)control focus?

or there easier approach (but still, on template level)?

p.s. problem can solved replacing contentpresenter label follows:

<label name="part_header"   content="{templatebinding header}"   contenttemplate="{templatebinding headertemplate}"   target="{binding relativesource={relativesource templatedparent}} /> 

but feel not 'right' way , i'm still missing fundamental, i'll happily listen suggestions.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -