WPF中的自定义文字包装

时间:2020-03-06 14:29:17  来源:igfitidea点击:

在WPF中是否可以将文本包装在非矩形容器中?

这是在Photoshop中完成的方法

解决方案

我们是否看过UIElement.Clip属性?

对于非矩形文字换行,我们可以尝试将TextBlock.Clip属性设置为非矩形Geometry对象。我还没有尝试过或者不会在剪辑区域之外绘制文本,或者将文本换行以适合剪辑。

查尔斯·皮佐德(Charles Petzold)提到了这项技术。

不幸的是,如果不完整地实现TextFormatter,就没有直接的方法。有关高级TextFormatter基础的MSDN文章:

The text layout and UI controls in WPF provide formatting properties that allow you to easily include formatted text in your application. These controls expose a number of properties to handle the presentation of text, which includes its typeface, size, and color. Under ordinary circumstances, these controls can handle the majority of text presentation in your application. However, some advanced scenarios require the control of text storage as well as text presentation. WPF provides an extensible text formatting engine for this purpose.