大纲/描边格式化文本

Fir*_*roz 2 wpf text-formatting

我正在使用不同的前景颜色将FormattedText呈现给不同的字符(例如前两个红色,接下来的两个黄色像..),现在我必须显示包围此文本的轮廓.对于应用轮廓(笔划),我必须将此FormattedText转换为几何体,然后绘制几何体

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

但问题是它会将FormattedText呈现为红色并丢失格式化颜色.我错过了什么,或者有另一种方式来概述文本.

Fir*_*roz 6

我想我找到了解决方案.首先绘制格式化文本然后绘制几何图形,它将显示文本以及轮廓.

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);
Run Code Online (Sandbox Code Playgroud)

如果有更好的方法,请告诉我.