views:

4308

answers:

4

I want to make the text displayed in the Witty, an open source Twitter client, selectable. It is currently displayed using a custom textblock. I need to use a TextBlock because I'm working with the textblock's inlines to display and format the @username and links as hyperlinks. A frequent request is to be able to copy-paste the text. In order to do that I need to make the TextBlock selectable.

I tried to get it to work by displaying the text using a read-only TextBox styled to look like a textblock but this will not work in my class because a TextBox does not have inlines. In order words, I can't style or format the text within a TextBox individually like I can with a TextBlock.

Any ideas?

+1  A: 

I'm not sure if you can make a TextBlock selectable, but another option would be to use a RichTextBox - it is like a TextBox as you suggested, but supports the formatting you want.

Bruce
This is the route I was planning to take next. thanks
Alan Le
I tried doing this, and in the process had to make the RichTextBox bindable with a dependency property. Unfortunately the old flowdocuments aren't being discarded properly and memory is leaking like crazy.Alan, I wonder if you found a way around this?
John Noonan
+7  A: 

Create ControlTemplate for the TextBlock and put a TextBox inside with readonly property set. Or just use TextBox and make it readonly, then you can change the TextBox.Style to make it looks like TextBlock

Jobi Joy
Interesting idea.. I'll give this a try.
Alan Le
Let me know if you need any help. cheers!
Jobi Joy
How do you set the ControlTemplate for a TextBlock ? I can't find the property ?
HaxElit
You can also set the style of the border it should look like a TextBlock. I think that a TextBox costs even less performance than a TextBlock, I think.
Shimmy
+4  A: 

nvm..

<TextBox Background="Transparent" BorderThickness="0" Text="{Binding Text}" IsReadOnly="True" TextWrapping="Wrap"/>

MSB
Thanks for that.
LnDCobra
A: 

There is an alternative solution that might be adaptable to the RichTextBox oultined in this blog post - it used a trigger to swap out the control template when the use hovers over the control - should help with performance

Richard