Search code examples
wpfxamlclipboard

TextBlock with selectable text AND copy all text to clipboard on click


Currently in my WPF app I have a multiple textbox readonly. So the user can select text and then Ctrl+C Ctrl+V. But I want to make this task more simple :

  • If the user just left click on the textbox (or another control that display my text), all the text is copy to clipboard

But the user still has the possibility to select the text as before

Any idea to do that in a XAML style ?


It is solve, I will automatically copy to clipboard any text selected. Knowing that if you doubleclick on a textbox it select all text, the user will just have to doubleclick to copy all the text in his clipboard.


Solution

  • For your clipboard problem, you can create an onclick handler and use the built-in clipboard functionality in C# (How to copy data to clipboard in C#).

    For the tooltip, you'll need to use an onload handler and the built-in tooltip functionality in C#:

    System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
    ToolTip1.SetToolTip(this.textBox1, "Hello");
    

    Haven't done much with animations, but if I'm not mistaken, you can set an onhover handler as well. (Edit: The MouseHover event handler is probably what you're looking for.)

    Edit: Basically, event handlers are your friends.