Files
docs-desktop/dotnet-desktop-guide/framework/wpf/advanced/how-to-create-text-with-a-shadow.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

4.1 KiB

title, ms.date, helpviewer_keywords, ms.assetid
title ms.date helpviewer_keywords ms.assetid
How to: Create Text with a Shadow 03/30/2017
typography [WPF], shadow effects
shadow effects in text [WPF]
text [WPF], shadowed
6ab9c754-6001-4708-b479-5367f2fd1a35

How to: Create Text with a Shadow

The examples in this section show how to create a shadow effect for displayed text.

Example

The xref:System.Windows.Media.Effects.DropShadowEffect object allows you to create a variety of drop shadow effects for [!INCLUDETLA#tla_winclient] objects. The following example shows a drop shadow effect applied to text. In this case, the shadow is a soft shadow, which means the shadow color blurs.

Text shadow with Softness = 0.25

You can control the width of a shadow by setting the xref:System.Windows.Media.Effects.DropShadowEffect.ShadowDepth%2A property. A value of 4.0 indicates a shadow width of 4 pixels. You can control the softness, or blur, of a shadow by modifying the xref:System.Windows.Media.Effects.DropShadowEffect.BlurRadius%2A property. A value of 0.0 indicates no blurring. The following code example shows how to create a soft shadow.

[!code-xamlTextShadowSnippets#TextShadowSnippet1]

Note

These shadow effects do not go through the [!INCLUDETLA#tla_winclient] text rendering pipeline. As a result, ClearType is disabled when using these effects.

The following example shows a hard drop shadow effect applied to text. In this case, the shadow is not blurred.

Text shadow with Softness = 0

You can create a hard shadow by setting the xref:System.Windows.Media.Effects.DropShadowEffect.BlurRadius%2A property to 0.0, which indicates that no blurring is used. You can control the direction of the shadow by modifying the xref:System.Windows.Media.Effects.DropShadowEffect.Direction%2A property. Set the directional value of this property to a degree between 0 and 360. The following illustration shows the directional values of the xref:System.Windows.Media.Effects.DropShadowEffect.Direction%2A property setting.

DropShadow degree setting of shadow

The following code example shows how to create a hard shadow.

[!code-xamlTextShadowSnippets#TextShadowSnippet2]

Using a Blur Effect

A xref:System.Windows.Media.Effects.BlurBitmapEffect can be used to create a shadow-like effect that can be placed behind a text object. A blur bitmap effect applied to text blurs the text evenly in all directions.

The following example shows a blur effect applied to text.

Text shadow using a BlurBitmapEffect

The following code example shows how to create a blur effect.

[!code-xamlTextShadowSnippets#TextShadowSnippet6]

Using a Translate Transform

A xref:System.Windows.Media.TranslateTransform can be used to create a shadow-like effect that can be placed behind a text object.

The following code example uses a xref:System.Windows.Media.TranslateTransform to offset text. In this example, a slightly offset copy of text below the primary text creates a shadow effect.

Text shadow using a TranslateTransform

The following code example shows how to create a transform for a shadow effect.

[!code-xamlTextShadowSnippets#TextShadowSnippet7]