WPF Image Command Binding

Total Post:119


 4453  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.

  1. 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" />

    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}" />

      Modified On Mar-31-2018 01:56:35 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.