WPF Image Command Binding -


i'm putting wpf application in have image control want bind custom command object view model execute when image clicked. have exposed command object view model , need bind image control.

is possible bind command object image control? if advice appreciated.

you need put image in button, , bind button command:

<button command="{binding mycommand}">     <image source="myimage.png" /> </button> 

if don't want standard button chrome, change template of button that:

<controltemplate x:key="tplflatbutton" targettype="{x:type button}">     <border width="{templatebinding width}"             height="{templatebinding height}"             background="{templatebinding background}"             borderbrush="{templatebinding borderbrush}"             borderthickness="{templatebinding borderthickness}">         <contentpresenter horizontalalignment="{templatebinding horizontalcontentalignment}"                           verticalalignment="{templatebinding verticalcontentalignment}"                           textelement.foreground="{templatebinding foreground}"                           textelement.fontfamily="{templatebinding fontfamily}"                           textelement.fontsize="{templatebinding fontsize}"                           textelement.fontstretch="{templatebinding fontstretch}"                           textelement.fontweight="{templatebinding fontweight}"/>     </border> </controltemplate> 

note need change other properties override default button style, otherwise template above use default button background , border:

<style x:key="stlflatbutton" targettype="{x:type button}">     <setter property="background" value="{x:null}" />     <setter property="borderbrush" value="{x:null}" />     <setter property="borderthickness" value="0" />     <setter property="template" value="{staticresource tplflatbutton}" /> </style> 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -