Questions tagged [textblock]

TextBlock is a WPF control for displaying small amounts of text.

TextBlock is a WPF control for displaying small amounts of text. It also allows to format parts of the content by using different Inlines (e.g. Run, Span, Hyperlink)

1073 questions
396
votes
10 answers

Automatic vertical scroll bar in WPF TextBlock?

I have a TextBlock in WPF. I write many lines to it, far exceeding its vertical height. I expected a vertical scroll bar to appear automatically when that happens, but it didn't. I tried to look for a scroll bar property in the Properties pane, but…
Bab Yogoo
  • 6,669
  • 6
  • 22
  • 17
265
votes
17 answers

Text vertical alignment in WPF TextBlock

How do I assign vertical center alignment to the text inside a TextBlock? I found TextAlignment property but it is for horizontal text alignment. How do I do it for vertical text alignment?
Ant
  • 3,369
  • 5
  • 25
  • 23
260
votes
20 answers

Any way to make a WPF textblock selectable?

How to allow TextBlock's text to be 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 case because a TextBox does not have inlines. In other words, how…
Alan Le
  • 8,683
  • 7
  • 36
  • 31
257
votes
4 answers

How to bind multiple values to a single WPF TextBlock?

I'm currently using the TextBlock below to bind the value of a property named Name: Now, I want to bind another property named ID to the same TextBlock. Is it possible to bind two or more values to the same…
Spen D
  • 4,225
  • 9
  • 39
  • 47
164
votes
5 answers

Difference between Label and TextBlock

According to the Windows Applications Development with Microsoft .NET 4 70-511 Training Kit What is the difference between the Label control and TextBlock control since both are content controls and just displaying text?
Rami Alshareef
  • 7,015
  • 12
  • 47
  • 75
133
votes
13 answers

How to put a new line into a wpf TextBlock control?

I'm fetching text from an XML file, and I'd like to insert some new lines that are interpreted by the textblock render as new lines. I've tried: Foo bar baz \n baz bar But the data is still displayed without the new line. I set the…
Only Bolivian Here
  • 35,719
  • 63
  • 161
  • 257
108
votes
16 answers

WPF Textblock, linebreak in Text attribute

Is there a way to have \n make a line break in a TextBlock? Or is there a better way to force a middle line break, inside the Text attribute? This doesn't work for me, it needs to be the value of the…
ScottCate
  • 2,365
  • 7
  • 21
  • 35
96
votes
3 answers

Force TextBlock to wrap in WPF ListBox

I have a WPF listbox which displays messages. It contains an avatar on the left side and the username and message stacked vertically to the right of the avatar. The layout is fine until the message text should word wrap, but instead I get a…
Eric Haskins
  • 8,505
  • 12
  • 38
  • 47
82
votes
2 answers

Is there any difference between WPF TextBlock and TextBox?

What criteria must I consider when selecting one of these two controls?
Irfan
  • 2,713
  • 3
  • 29
  • 43
78
votes
3 answers

WPF format DateTime in TextBlock?

I have a TextBlock that is bound to a DateTime property. How do I configure the format of the date?
Peter
  • 37,042
  • 39
  • 142
  • 198
74
votes
4 answers

Programmatically set TextBlock Foreground Color

Is there a way to do this in Windows Phone 7? I can reference the TextBlock in my C# Code, but I don't know exactly how to then set the foreground color of it. myTextBlock.Foreground = //not a clue... Thanks
user818700
71
votes
4 answers

WPF TextBlock Underline

I have a textblock of width say 500, but my string is just say "H" but I want to underline the whole textblock width not just under H what can I do?
user679530
  • 897
  • 1
  • 8
  • 11
69
votes
6 answers

Having hardcoded text with a binding in a TextBlock

In WPF, is there any way to have the Text property of a TextBlock to contain both hard coded text and a specific binding? What I have in mind is something along the lines of the following (ofcourse, the below doesn't compile):
Andreas Grech
  • 105,982
  • 98
  • 297
  • 360
66
votes
3 answers

How to a add a command to a WPF TextBlock?

I'd like to be able to click a textblock and have it run a Command. Is this possible? (if not do I just somehow make a tranparent button over it or something?)
Shai UI
  • 50,568
  • 73
  • 204
  • 309
63
votes
7 answers

WPF TextBlock font resize to fill available space in a Grid

I have some text that is displayed at run time in a textblock. I want the font size to be the biggest it can be to fill the area that is given. I think I have the textblock setup correctly to "autosize" and I try to increase the font size till the…
Nate Zaugg
  • 4,202
  • 2
  • 36
  • 53
1
2 3
71 72