Home > DeveloperSection > Forums > WPF Image Command Binding
Goti Bandu

Total Post:119

Points:835
Posted on    September-25-2013 3:04 AM

 WPF WPF 
Ratings:


 1 Reply(s)
 2714  View(s)
Rate this:

I'm putting a WPF application together in which I have an image control which I want to bind a custom command object to from my view model that will execute when the image is clicked. I have exposed the command object from my view model and just need to bind it to the image control.

Is it possible to bind this command object to an image control? If so any advice would be appreciated.



ezra heywood
ezra heywood

Total Post:145

Points:1019
Posted on    September-25-2013 4:26 AM

Hi Goti,

It can be simpler to avoid using a button and use a Hyperlink instead:

<TextBlock DockPanel.Dock="Top">

   <Hyperlink Command="{Binding SomeCommand}">

      <Image Source="image.png" />

   </Hyperlink>

</TextBlock>

Note that this will render the hyperlink with the default text decoration, so you'll want to add a style that removes that - putting this in the resource dictionary of the containing element will do the trick:

<Style x:Key={x:Type Hyperlink}" TargetType="Hyperlink">

   <Setter Property="TextDecorations"

           Value="{x:Null}" />

   </Style>

</Style>


Modified On Apr-04-2016 11:01:59 PM

Don't want to miss updates? Please click the below button!

Follow MindStick