Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Image Command Binding

Tags:

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.

like image 385
David Avatar asked Oct 07 '10 19:10

David


People also ask

What is command binding in WPF?

The command is the action to be executed. The command source is the object which invokes the command. The command target is the object that the command is being executed on. The command binding is the object which maps the command logic to the command.

What is the use of ICommand in WPF?

Commands provide a mechanism for the view to update the model in the MVVM architecture. Commands provide a way to search the element tree for a command handler.


1 Answers

Here's yet another solution I personally love to use most of the time if I want an image with command without enclosing it in another control.

<Image Source="Images/tick.png" Cursor="Hand" Tooltip="Applies filter">      <Image.InputBindings>           <MouseBinding Gesture="LeftClick" Command="{Binding ApplyFilter, Mode=OneTime}" />      </Image.InputBindings> </Image> 

I set its properties Hand and Tooltip so that it's more clear that it's an action and not a static image.

like image 63
Ondrej Janacek Avatar answered Oct 05 '22 12:10

Ondrej Janacek