Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF textbox and doubleclick

I am displaying Mac Address in a WPF application. I want that mac address to be selectable to be copy/paste, so I am using ReadOnly TextBox

When the user double click I want to select the whole MacAddress

The default behavior by the WPF and Windows, is by double click select part of the number between colons so when the mac address is : 00:55:66:77:99

and the user double click, only one part of the mac address (like 55) being selected Is there a way without a code to make the selection for the whole content for textbox

or maybe I should not use textbox?

Thanks

like image 928
Ghassan Karwchan Avatar asked Dec 03 '09 18:12

Ghassan Karwchan


1 Answers

On MouseDoubleClick event of textbox you can call SelectAll() method of textbox to select al the text inside it.

void textBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    (sender as TextBox).SelectAll();
}
like image 171
viky Avatar answered Sep 23 '22 21:09

viky