silverlight - Reference ViewModel's DataContext from within a DataTemplate in a DataTemplate -


i found myself in bit of bind... bindings... hehe... (lame)

anyway... need refer main viewmodel's property, within datatemplate, within datatemplate... , looks relativesource mode silverlight allows are: self , templatedparent. , templatedparent doesn't go enough.

is there can done?

some code:

<phone:panoramaitem>     <phone:longlistselector margin="0,-38,-22,2" itemssource="{binding items}">         <phone:longlistselector.itemtemplate>             <datatemplate>                 <common:itemcontenttemplateselector datacontext="{binding}" content="{binding itemcontent}" horizontalcontentalignment="stretch" margin="12,2,0,4">                     <common:itemcontenttemplateselector.defaulttemplate>                         <datatemplate>                             .....                         </datatemplate>                     </common:itemcontenttemplateselector.defaulttemplate>                     <common:itemcontenttemplateselector.phonenumbertemplate>                         <datatemplate>                             <grid background="white" height="102">                                 <border x:name="border">                                     <textblock text="call"/>                                     <i:interaction.triggers>                                         <i:eventtrigger eventname="mouseleftbuttondown">                                      <!-- binding error -->                                             <i:invokecommandaction command="{binding relativesource={relativesource mode=templatedparent}, path=datacontext.phonecallcommand}"/>                                         </i:eventtrigger>                                     </i:interaction.triggers>                                 </border>                             </grid>                         </datatemplate>                     </common:itemcontenttemplateselector.phonenumbertemplate>                 </common:itemcontenttemplateselector>             </datatemplate>         </phone:longlistselector.itemtemplate>     </phone:longlistselector> </phone:panoramaitem> 

if don't wont workaround or make easily, there do;

using staticresource

have @ this;

   myviewmodelclass viewmodel    {         get;set;    }    ...ctor()   {      this.viewmodel=new myviewmodelclass();      this.datacontext=this.viewmodel; //we use same vm instance datacontext resource      this.resoureces.add("mainviemodel",viewmodel);      initializecomponents();//...add resource before line   } 

after can use viewmodel @ same time staticresource anywhere want;

{binding path=items,source={staticresource viewmodel}} 

i coded on stackoverflow's editor. there missing chars ...


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -