Files
docs-desktop/dotnet-desktop-guide/framework/wpf/advanced/how-to-enable-text-trimming.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

2.8 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Enable Text Trimming 03/30/2017
csharp
vb
text [WPF], trimming
documents [WPF], trimming text
trimming text [WPF]
dd8c9191-d2be-45fd-9fb4-3c75b65578c5

How to: Enable Text Trimming

This example demonstrates the usage and effects of the values available in the xref:System.Windows.TextTrimming enumeration.

Example

The following example defines a xref:System.Windows.Controls.TextBlock element with the xref:System.Windows.Controls.TextBlock.TextTrimming%2A attribute set.

[!code-xamlTextTrimmingSnippets#_TextTrimmingXAML]

Setting the corresponding xref:System.Windows.TextTrimming property in code is demonstrated below.

[!code-csharpTextTrimmingSnippets#_TextTrimmingSetTextTrimming] [!code-vbTextTrimmingSnippets#_TextTrimmingSetTextTrimming]

There are currently three options for trimming text: CharacterEllipsis, WordEllipsis, and None.

When xref:System.Windows.Controls.TextBlock.TextTrimming%2A is set to CharacterEllipsis, text is trimmed and continued with an ellipsis at the character closest to the trimming edge. This setting tends to trim text to fit more closely to the trimming boundary, but may result in words being partially trimmed. The following figure shows the effect of this setting on a xref:System.Windows.Controls.TextBlock similar to the one defined above.

Example: TextTrimming.CharacterEllipsis

When xref:System.Windows.Controls.TextBlock.TextTrimming%2A is set to WordEllipsis, text is trimmed and continued with an ellipsis at the end of the first full word closest to the trimming edge. This setting will not show partially trimmed words, but tends not to trim text as closely to the trimming edge as the CharacterEllipsis setting. The following figure shows the effect of this setting on the xref:System.Windows.Controls.TextBlock defined above.

Example: TextTrimming.WordEllipsis

When xref:System.Windows.Controls.TextBlock.TextTrimming%2A is set to None, no text trimming is performed. In this case, text is simply cropped to the boundary of the parent text container. The following figure shows the effect of this setting on a xref:System.Windows.Controls.TextBlock similar to the one defined above.

Example: TextTrimming.None