2010-03-31 1 views
11

Avec WPF4 vous pouvez avoir un texte non flou en ajoutant TextOptions.TextFormattingMode = "Affichage" et TextOptions.TextRenderingMode = "Aliased" à votre XAML:En utilisant TextOptions.TextFormattingMode avec FormattedText

<Window 
    TextOptions.TextFormattingMode="Display" 
    TextOptions.TextRenderingMode="Aliased"> 

Cela fonctionne très bien pour moi, sauf quand je dessine du texte avec DrawingContext.DrawText comme ceci:

void DrawText(DrawingContext dc) 
{ 
    FormattedText ft = new FormattedText("Hello World", 
    System.Globalization.CultureInfo.CurrentCulture, 
    System.Windows.FlowDirection.LeftToRight, 
    new Typeface(FontFamily, FontStyle, FontWeight, FontStretch), 
    FontSize, 
    brush); 
    dc.DrawText(ft, new Point(rect.Left, rect.Top)); 
} 

Comment puis-je dessiner le texte non-flou avec FormattedText? c'est-à-dire que je veux TextOptions.TextFormattingMode = "Display" et TextOptions.TextRenderingMode = "Aliased" à utiliser.

Répondre

12

Il y a un constructeur surchargé pour FormattedText qui permet de spécifier un TextFormattingMode: http://msdn.microsoft.com/en-us/library/ee474866.aspx

void DrawText(DrawingContext dc) 
{ 
    FormattedText ft = new FormattedText("Hello World", 
    System.Globalization.CultureInfo.CurrentCulture, 
    System.Windows.FlowDirection.LeftToRight, 
    new Typeface(FontFamily, FontStyle, FontWeight, FontStretch), 
    FontSize, 
    brush, 
    null, 
    TextFormattingMode.Display); 
    dc.DrawText(ft, new Point(rect.Left, rect.Top)); 
} 
+3

Cette réponse est bonne, pourquoi quelqu'un l'a rejeté? – asktomsk

+0

+1. Je suis d'accord, cette réponse est certainement juste et je ne peux pas voir une raison pour une downvote. Il ne spécifie pas comment définir TextRenderingMode –