Double clicks and commands from code

Topics: Prism v2 - Silverlight 2
Jul 13, 2009 at 6:34 PM
Edited Jul 14, 2009 at 2:10 AM

Hello,

I am struggling to get my mind around adding a double click behavior that fires off a command. I am using SL3 and Prism of course.

In my PresentationModel class, I am adding panels to a canvas in my region that contains BitmapImage objects. This is not done from XAML but from code that adds the panels and bitmaps as child objects. The reason for this is another topic all together.

How can I attach a behavior which handles clicks and double clicks that generates a command? All the sample code I can find does this from XAML and not from code.

Thank you in advance.

Rick

Jul 15, 2009 at 1:29 PM

Hi Rick,

If I understand correctly, you want to be able to fire a command based on a double click/click from the user. This command should be fired from code behind.

In this scenario, you should take into account that a behavior’s goal is to be able to hook the command to a particular control from XAML. (You can read more about it here). Therefore, if you want to execute a particular piece of code every time the click/double click happens, you can simply subscribe to the click event in the code behind and implement the logic. If you want to execute a command, you can simply call the command’s execute method.

In case you want to use a behavior for click or double click (from XAML), this thread provides some information on how to do it.

Please let me know if this helps.

Damian Schenkelman

http://blogs.southworks.net/dschenkelman

Jul 15, 2009 at 5:42 PM

Hi Damian,

I was heading down that route but thought I might be missing something.

Are you avalable to write any custom controls? I have an interesting project for you if you are available.

Thank you,

Rick