Formatted Text Outline / Stroke

I formatted the FormattedText with a different foreground color to a different character (for example the first two are red, the next 2 are yellow as ..), now I need to display the outline surrounded by that text. To apply outline (stroke) I need to convert this FormattedText to geometry and then draw geometry like

Geometry textGeometry = FormattedText.BuildGeometry (new point (_xOffset, _yOffset)); drawingContext.DrawGeometry (null, new Pen (new SolidColorBrush (OutlineColor), storkeWidth), textGeometry);

but the problem is that it will display the FormattedText in red and lose my formatting color. Am I missing something or is there another way to draw the text.

+2


source to share


1 answer


I think I have found a solution. draw the formatted text first and then the geometry, it will display the text the same as the outline.

Geometry textGeometry = FormattedText.BuildGeometry(new Point(_xOffset, _yOffset)); 
drawingContext.DrawText(FormattedText,new Point(0,0));
drawingContext.DrawGeometry(null, new Pen(new SolidColorBrush(OutlineColor), storkeWidth),textGeometry);

      



If anyone has a better approach please let me know.

+6


source







All Articles