Bewerken

Share via


RenderOptions.ClearTypeHint Attached Property

Definition

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

see GetClearTypeHint, and SetClearTypeHint
see GetClearTypeHint, and SetClearTypeHint
see GetClearTypeHint, and SetClearTypeHint

Examples

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>  

Remarks

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.

Note

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

Note

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.

Applies to