Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Text Wrapping in WPF

Tags:

text

wpf

Is there a way of wrapping text in a non-rectangular container in WPF?

Here is how it is done in photoshop

like image 288
viggity Avatar asked Sep 20 '08 16:09

viggity


2 Answers

Have you looked at the UIElement.Clip property?

For non-rectangular text wrapping, you could try setting a TextBlock.Clip property to a non-rectangular Geometry object. I haven't tried this; either it will not draw text outside the clip region or it will wrap text to fit within the clip.

Charles Petzold mentions this technique.

like image 24
Judah Gabriel Himango Avatar answered Sep 28 '22 12:09

Judah Gabriel Himango


Unfortunately there isn't a straightforward way without making a complete implementation of a TextFormatter. MSDN article on the basics of an Advanced TextFormatter:

The text layout and UI controls in WPF provide formatting properties that allow you to easily include formatted text in your application. These controls expose a number of properties to handle the presentation of text, which includes its typeface, size, and color. Under ordinary circumstances, these controls can handle the majority of text presentation in your application. However, some advanced scenarios require the control of text storage as well as text presentation. WPF provides an extensible text formatting engine for this purpose.

like image 133
user7116 Avatar answered Sep 28 '22 11:09

user7116