c# - Using a ValueConverter after a DataContext switch -


i want try out small, custom valueconverter in class after being instantiated (via default constructor, calls initializecomponents() ), given datacontext, instance of viewmodel.

using staticresource within binding not work @ (yields nullreferenceexception), since datacontext has since been changed (is not this anymore).

i've tried putting datacontext = this; before initializecomponents call, no change. should looking markupextension gizmo (as described in article) ?

i've tried creating instance of custom value converter within viewmodel (the current datacontext), doesn't either.

i can provide additional details @ times. thank in advance !

i'm trying display contextmenu within textblock. contextmenu contains sole menuitem. header of menuitem can "settings" instance. children (rendered menuitems well) of said menuitem stem enum, hence itemssource on menuitem.

now getting displayed nicely, yet trying make 1 of children (e.g. member of enum) selected per default, since there default setting. further background info can found in my other question.

edit :

...  <usercontrol.resources>   <helpers:displaytypetodefaultvalueconverter x:key="displaytypeconverter" /> </usercontrol.resources> ...  <textblock x:name="instructionlabel"             textwrapping="wrap" text="{binding path=selectednodetext}"             grid.rowspan="1">    <textblock.contextmenu>     <contextmenu>       <menuitem header="settings" name="settingspop"                  datacontext="{binding}"                  itemssource="{binding source={staticresource displaytypevalues}}"                 ischeckable="true"                 click="settingstype_click">             <menuitem.itemcontainerstyle>           <style targettype="menuitem">             <setter property="header" value="{binding}"/>             <setter property="ischecked">               <setter.value>                 <binding converter="{staticresource displaytypeconverter}" />               </setter.value>             </setter>           </style>         </menuitem.itemcontainerstyle>        </contextmenu>   </textblock> 

i've realized it's dreaded contextmenu. that's problem, isn't ?

the datacontext inside itemcontainerstyle member of displaytypevalues collection. thing in xaml posted affected datacontext of usercontrol changing instructionlabel's text. setting datacontext="{binding}" you're doing on menuitem redundant value inherited parent contextmenu.

it's not clear question or code you're expecting datacontext or you're trying it.


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? -