tags:

views:

218

answers:

4

i want to copy content of one text box to another text box by clicking the mouse.

how do i bind a mouse click event?

A: 

I think you could bind mouse gestures to commands. Take a look at this: http://www.thejoyofcode.com/Invoking_a_Command_on_a_Double_Click_or_other_Mouse_Gesture.aspx

AndrewS
A: 

I'm not sure what exactly you're wanting to bind to.

There is no readily available MouseClick event as far as i'm aware.

the Click event as you'd find on a Button is inherited from ButtonBase and is not readily available on most controls.

MouseDoubleClick is inherited from Control and available on anythning deriving from it.

in your example it sounds like a simple Button with its Click event handled might do the trick.

To bind to the click event, you just need to specify the event handler for the event in the Button.

Something like:

XAML:

<TextBox Name=TextBoxOne />
<TextBox Name=TextBoxTwo />

<Button Click="CopyTextButton_Click"/>

And in your code behind:

void CopyTextButton_Click(object sender, RoutedEventArgs e)
{
    //Copy the text and anything else you need done
}

Otherwise if this is a more specialised scenario, you might want to investigate using a UserControl or as AndrewS answered above, a Command.

Hope it helps.

Val
ok thx. im thinking of putting a button 'behind' the textbox (custom textbox + button user control) to achieve this. So when the user clicks on the text, the button gets the event... thx guys for the help. i will try this out.
+1  A: 

It sounds like you are inventing a new behaviour for your textbox :)

I would just consider if the users of your program understands and likes this behaviour.

Maybe it is easier to understand the funcionality if it is just a button you have to click - it is also faster to implement :)

Rune Andersen
+1. I hate apps that try to be *too* innovative with their interaction schemes
Isak Savo
+1  A: 

Hello,

Want to add a behavior to a control ? Just use the Ramora pattern !

Jmix90
+1 for Ramora pattern.
Val