WPF IMAGE COMMAND BINDING

Goti Bandu

Total Post:119

Points:835
Posted by  Goti Bandu
WPF 
WPF
 3602  View(s)
Ratings:
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.

  1. ezra heywood

    Post:145

    Points:1019
    Re: WPF Image Command Binding

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!