Export (0) Print
Expand All

RenderOptions.ClearTypeHint Attached Property

Gets or sets a value that indicates to the rendering engine whether text can be rendered with ClearType.

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

See GetClearTypeHint, SetClearTypeHint
<object RenderOptions.ClearTypeHint="ClearTypeHint" .../>

Property Value

Type: System.Windows.Media.ClearTypeHint
A System.Windows.Media.ClearTypeHint that indicates whether text can be rendered with ClearType.

Use the ClearTypeHint attached property to indicate that text can be rendered with ClearType in a specific part of the visual tree.

ClearType text does not display correctly on a background that is not fully opaque. Intermediate render targets, such as Effect, OpacityMask, VisualBrush, DrawingBrush, Clip, and Opacity, can introduce backgrounds that are not fully opaque. WPF disables ClearType when it detects that the buffer into which text is drawn could have a transparent background.

Set the ClearTypeHint property to Enabled to indicate that a subtree is safe for ClearType text rendering. Do this only when you can be certain that the text is rendering to a fully opaque background. When an element in the subtree introduces transparency, you can enable ClearType; however, rendering issues may occur. If a portion of the subtree introduces more intermediate rendering targets, you must set ClearTypeHint again on the children of that subtree.

The following list shows how to make sure that text to be rendered with ClearType appears correctly.

  • Do not introduce intermediate render targets between ClearTypeHint and the text to be rendered with ClearType.

  • Assign an opaque background that is as close as possible in the visual tree to the text.

  • Be aware that ClearTypeHint re-enables ClearType for a subtree; however, it does not force ClearType rendering.

  • Be aware that ClearTypeHint does not override your system settings or TextRenderingMode settings.

NoteNote

The ClearTypeHint attached property does not affect the TextBox control; however, it does work with the TextBlock control.

NoteNote

On many controls, the ClearTypeHint attached property has no effect unless you set an opaque background behind the text.

To access this property in code, use the GetClearTypeHint and SetClearTypeHint methods.

The following example shows how the ClearTypeHint property affects different branches of the visual tree. In the first text block control, text is rendered with ClearType because the text block inherits the setting from the main window. In the second text block, ClearType is not used because the parent element's OpacityMask property is set. In the third text block, ClearTypeHint is used, but rendering issues may occur.

    <Window x:Class="ClearTypeHintDemo.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300"
        AllowsTransparency="True" 
        WindowStyle="None" 
        RenderOptions.ClearTypeHint="Enabled" Background="White">
    <Window.Resources>
        <LinearGradientBrush x:Key="opacityBrush" >
            <GradientStop Color="#FF000000" Offset="0.0" />
            <GradientStop Color="#00000000" Offset="1.0" />
        </LinearGradientBrush>
    </Window.Resources>

    <StackPanel>
        <TextBlock Text="This text is rendered with ClearType." />
        <StackPanel OpacityMask="{StaticResource opacityBrush}" >
            <TextBlock Text="This text is not rendered with ClearType." />
            <TextBlock RenderOptions.ClearTypeHint="Enabled" 
                       Text="This text is rendered with ClearType but may alpha-blend incorrectly." />
        </StackPanel>
    </StackPanel>
</Window>

.NET Framework

Supported in: 4.5, 4

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft