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
59
votes
2 answers

WPF Multiline TextBlock CenterAlignment Issue

I'm having an issue with multiline text blocks where it is not center aligning properly The text is coming like abcde\nabc This comes out abcde abc What I want is abcde abc This seems a simple thing and I would have thought that the…
John
  • 1,286
  • 2
  • 14
  • 22
55
votes
4 answers

Binding to static class property

I want to bind a textblock text to a property of a static class. Whenever the property value of the static class changes, it should reflect to the textblock which is on the other window or custom control.
Vinod Maurya
  • 4,167
  • 11
  • 50
  • 81
49
votes
5 answers

How can I determine if my TextBlock text is being trimmed?

The following textblock wraps and trims as expected. The elipsis "..." is displayed when the text is trimmed.
Andrew Jackson
  • 764
  • 1
  • 7
  • 13
44
votes
4 answers

Add hyperlink to textblock WPF

I have some text in a db and it is as follows: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis tellus nisl, venenatis et pharetra ac, tempor sed sapien. Integer pellentesque blandit velit, in tempus urna semper sit amet. Duis mollis,…
niao
  • 4,972
  • 19
  • 66
  • 114
41
votes
8 answers

How to make all text upper case / capital?

I want all texts in TextBlock, Label, MenuItem.Header to be displayed in upper case. The strings are taken from a ResourceDictionary e.g.:
GG.
  • 413
  • 1
  • 4
  • 4
37
votes
2 answers

TextBlock with multiple spacing

Given a formatted text block in Windows Phone 7.1 project:
Maxim V. Pavlov
  • 10,303
  • 17
  • 74
  • 174
37
votes
10 answers

Data binding the TextBlock.Inlines

My WPF App receives a stream of messages from a backend service that I need to display in the UI. These messages vary widely and I want to have different visual layout (string formats, colors, Fonts, icons, whatever etc.) for each message. I was…
will
  • 3,975
  • 6
  • 33
  • 48
32
votes
1 answer

How to grow/shrink a TextBlock (Font Size) to the available space in WPF?

I've seen this question asked a lot, however, to the opposite of what I'm looking for. While other people want a control to size itself based on the size of text, I'm trying to figure out is if there is a way to grow the size of text to the amount…
Greg Andora
  • 1,372
  • 2
  • 11
  • 17
32
votes
7 answers

Maximum number of lines for a Wrap TextBlock

I have a TextBlock with the following setting: TextWrapping="Wrap" Can I determine the maximum number of lines? for example consider the following string TextBlock.Text: This is a very good horse under the blackboard!! It currently has been shows…
MBZ
  • 26,084
  • 47
  • 114
  • 191
30
votes
3 answers

How to remove additional padding from a WPF TextBlock?

By default a WPF TextBlock seems to have additional top and bottom padding applied. I wish this wasn't so. I've tried setting negative padding, but got an exception: 0,-10,0,0' is not a valid value for property 'Padding'. I've tried setting the…
Gleno
  • 16,621
  • 12
  • 64
  • 85
30
votes
6 answers

Adding text to a bound TextBlock

I would like to prepend a text in a data-bound text block: The text that is shown is: "My title" What I want to be shown is: This is "My title"
Rhys
  • 2,807
  • 8
  • 46
  • 68
30
votes
6 answers

How to detect a change in the Text property of a TextBlock?

Is there any way to detect a change in the Text property of a TextBlock element using events? (I'm trying to provide an animation for highlighting the TextBlocks whose Text property change within a DataGrid)
John Parker
30
votes
1 answer

TextBlock.TextWrapping - how to make the text wrap so that the lines are center-aligned?

In a Windows Phone 7 application, when I place a TextBlock in the grid and set its HorizontalAlignment to "Center" and its TextWrapping to "Wrap", why does the text that overflows the width of the container and is placed on the next line, align with…
Peter Perháč
  • 20,434
  • 21
  • 120
  • 152
28
votes
8 answers

How to bind a TextBlock to a resource containing formatted text?

I have a TextBlock in my WPF window. Some formatted text. When it is rendered it looks like this, Some formatted text. My question is, can I bind this inline "content" to a resource in my…
Jodrell
  • 34,946
  • 5
  • 87
  • 124
28
votes
3 answers

Set TextBlock to be entirely bold when DataBound in WPF

I have a databound TextBlock control (which is being used inside a DataTemplate to display items in a ListBox) and I want to make all the text in the control bold. I can't seem to find a property in the properties explorer to set the whole text to…
robintw
  • 27,571
  • 51
  • 138
  • 205
1
2
3
71 72