在WPF中,是否有一种简单的方法可以向FlowDocument
元素添加波浪下划线(如Word中的拼写错误)?这是Underline
班级,但似乎没有办法来设计它.
您可以使用Robert Macne解决方案的以下更改来创建波浪效果
将可视化画笔添加到Grid.Resources部分:
并将笔更改为:
红色下划线很简单:
一个波浪红色下划线会更复杂一些,但我想你可以创建一个有红色波浪事情VisualBrush,并设置为钢笔的画笔,指定强调TextDecoration. 编辑:请参阅bstoney的帖子.
这是@ bstoney在代码中实现的解决方案.
Pen path_pen = new Pen(new SolidColorBrush(Colors.Red), 0.2); path_pen.EndLineCap = PenLineCap.Square; path_pen.StartLineCap = PenLineCap.Square; Point path_start = new Point(0, 1); BezierSegment path_segment = new BezierSegment(new Point(1, 0), new Point(2, 2), new Point(3, 1), true); PathFigure path_figure = new PathFigure(path_start, new PathSegment[] { path_segment }, false); PathGeometry path_geometry = new PathGeometry(new PathFigure[] { path_figure }); DrawingBrush squiggly_brush = new DrawingBrush(); squiggly_brush.Viewport = new Rect(0, 0, 6, 4); squiggly_brush.ViewportUnits = BrushMappingMode.Absolute; squiggly_brush.TileMode = TileMode.Tile; squiggly_brush.Drawing = new GeometryDrawing(null, path_pen, path_geometry); TextDecoration squiggly = new TextDecoration(); squiggly.Pen = new Pen(squiggly_brush, 6); text_box.TextDecorations.Add(squiggly);