How to get property values from ancestor controls far away in a complex WPF visual tree, in XAML? -


for starters, barely know i'm doing.

i'd reach control that's pretty far away in visual tree property value it. it's contentcontrol , property istabstop. i'm in user control heavily re-used in variety of places different tree structures. since tree structure variable, don't think can use findancester type of "contentcontrol" (can't predict how many intermediate contentcontrols in tree).

the control i'm looking in datatemplate used display item in itemscontrol. though there's unique name, attempt snag property value elementname binding didn't work either. (it seems have picked wrong value.)

there more 1 itemscontrol in picture (meaning, may or may not inside secondary itemscontrol), don't think can use variant of "." (even if smart enough think of one).

is there way can in xaml, or asking xaml much? should explicitly creating appropriate binding in code-behind?


edit, 27 apr:

tl;dr: looks elementname right approach. guess gets resolved in way have written procedural code (and in way similar how javaserver faces it): walking tree until find scope containing named element (which close enough "walking tree until hit" -government work- hackery). see http://blogs.msdn.com/b/mikehillberg/archive/2008/05/23/of-logical-and-visual-trees-in-wpf.aspx (editorial note microsoft: why piece of info need in blog entry? supposed reading source code? @ least sun laid out in spec.)

i agree don't need procedural code, but....

stuff i've tried:

iconstoolsbar.xaml:

<usercontrol>   <grid><grid><border><grid>     <!-- fail.  defaults true, ignores ancestor values (apparently). -->     <button/>     <!-- fail.  snoop reports binding error (red highlight) -->     <button istabstop="{binding relativesource={relativesource templatedparent}, path=istabstop}"/>     <!-- um, well... seems work.  why?  "formelement" occurs multiple times virtue of fact we're          in itemscontrol.     -->     <button istabstop="{binding istabstop, elementname=formelement}"/>   </grid></border></grid></grid> </usercontrol> 

separate resource file. note "dictionary" object can occur inside itemscontrol not shown.

<resourcedictionary>   <datatemplate x:key="multiselectlistdictionarydatatemplate">     <grid>       <toolbars:iconstoolbar datacontext="{binding iconstoolbarcontroller}"/>       <!-- other stuff -->     </grid>   </datatemplate>    <datatemplate datatype="{x:type viewmodels:obssuggesteddictionaryviewmodel}">     <contentpresenter x:name="dictionarypresenter"                       content="{binding relativesource={relativesource templatedparent}, path=content}"                       contenttemplate="{staticresource dropdownsingledictionarydatatemplate}" />     <datatemplate.triggers>       <multidatatrigger>         <multidatatrigger.conditions>           <condition binding="{binding displayformat}" value="vertical"/>           <condition binding="{binding selectiontype}" value="multi select"/>         </multidatatrigger.conditions>         <setter targetname="dictionarypresenter" property="contenttemplate" value="{staticresource multiselectlistdictionarydatatemplate}"/>       </multidatatrigger>     </datatemplate.triggers>   </datatemplate> </resourcedictionary> 

this 3rd separate file has user control contains objects of various types, including "dictionary" type above, want display. note layoutpart contained in yet itemscontrol, i'm not going lay tree out far up, because here data want lives.

<resourcedictionary>   <datatemplate x:key="multiselectlistdictionarydatatemplate">     <grid>       <toolbars:iconstoolbar datacontext="{binding iconstoolbarcontroller}"/>       <!-- other stuff -->     </grid>   </datatemplate>    <datatemplate datatype="{x:type viewmodels:obssuggesteddictionaryviewmodel}">     <contentpresenter x:name="dictionarypresenter"                       content="{binding relativesource={relativesource templatedparent}, path=content}"                       contenttemplate="{staticresource dropdownsingledictionarydatatemplate}" />     <datatemplate.triggers>       <multidatatrigger>         <multidatatrigger.conditions>           <condition binding="{binding displayformat}" value="vertical"/>           <condition binding="{binding selectiontype}" value="multi select"/>         </multidatatrigger.conditions>         <setter targetname="dictionarypresenter" property="contenttemplate" value="{staticresource multiselectlistdictionarydatatemplate}"/>       </multidatatrigger>     </datatemplate.triggers>   </datatemplate> </resourcedictionary> 

(it's unfortunate we're calling our objects "dictionaries". it's "for historical reasons".)

obssuggesteddictionaryviewmodel subclass of class has property tells whether want thing tab stop or not.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -