wpf - Passing BitmapImage as Tag to DataTemplate -


i'm bit unexperienced in wpf , trying simple template in wpf button image icon in addition text work.

style code:

<style x:key="databasebuttonwithimagetag" targettype="button" basedon="{staticresource databasebutton}">     <setter property="contenttemplate">         <setter.value>             <datatemplate>                 <grid>                     <grid.columndefinitions>                         <columndefinition width="1*" />                         <columndefinition width="2*" />                     </grid.columndefinitions>                      <image grid.column="0" width="100" source="{templatebinding tag}" />                     <contentcontrol grid.column="1" content="{templatebinding content}" />                  </grid>             </datatemplate>         </setter.value>     </setter> </style> 

view code:

       <image source="{staticresource image_new_patient}"/>     <button style="{staticresource databasebuttonwithimagetag}" tag="{staticresource image_new_patient}" width="150" height="100">         test!     </button> 

the image outside button displayed, "test!", there no image inside button.

what doing wrong?

templatebinding not work within datatemplate.

you can use workaroud:

 <window.resources>     <bitmapimage x:key="image_new_patient" urisource="bsp.jpg" />     <local:imageconverter x:key="imageconverter" />     <style x:key="databasebuttonwithimagetag" targettype="button">         <setter property="contenttemplate">             <setter.value>                 <datatemplate>                     <grid>                         <grid.columndefinitions>                             <columndefinition width="1*" />                             <columndefinition width="2*" />                         </grid.columndefinitions>                          <image grid.column="0" width="100" source="{binding relativesource={relativesource ancestortype=button}, path=tag}"  />                          <contentcontrol grid.column="1" content="{templatebinding content}" />                     </grid>                 </datatemplate>             </setter.value>         </setter>     </style>  </window.resources> <stackpanel>     <image source="{staticresource image_new_patient}" width="50"/>     <button style="{staticresource databasebuttonwithimagetag}" tag="{staticresource image_new_patient}" width="150" height="100">         test!     </button>  </stackpanel> 


Comments

Popular posts from this blog

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

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -