如何扩展 TextBlock 以显示大纲文本?

How can I extend a TextBlock to display Outlined Text?

我的问题与 this 问题有关。

这个问题比较陈旧,答案比较陈旧,感觉有些欠缺。用户从头开始创建了一个有些欠缺的控件,但最重要的是,感觉没有必要(至少对我而言)创建一个全新的控件来拥有一个可以支持的 TextBlock描边(轮廓)文本。

我正在尝试通过提供画笔 属性 和双画笔 属性 来扩展 TextBlock 控件。我曾希望我可以覆盖 OnRender 方法,但它是密封的,所以我不能。

这是我目前所拥有的(不多):

public class StrokedText: TextBlock {
    public static readonly DependencyProperty
        StrokeProperty = DependencyProperty.Register(
            "Stroke",
            typeof( Brush ),
            typeof( StrokedText ),
            new PropertyMetadata(
                Brushes.Red,
                ( S, E ) => ( S as StrokedLabel ).InvalidateVisual( ) ) ),
        StrokeWidthProperty = DependencyProperty.Register(
            "StrokeWidth",
            typeof( double ),
            typeof( StrokedText ),
            new PropertyMetadata(
                2.0D,
                ( S, E ) => ( S as StrokedLabel ).InvalidateVisual( ) ) );

    /// <summary>
    /// Get or Set Stroke Brush.
    /// </summary>
    public Brush Stroke {
        get { return this.GetValue( StrokeProperty ) as Brush; }
        set { this.SetValue( StrokeProperty, value ); }
    }

    /// <summary>
    /// Get or Set Stroke Width
    /// </summary>
    public double StrokeWidth {
        get { return ( double )this.GetValue( StrokeWidthProperty ); }
        set { this.SetValue( StrokeWidthProperty, value ); }
    }

我花了一些时间查看 TextBlock 控件,以便跟踪它实际在屏幕上将字符串呈现为文本的位置(我想如果我能找到我可以复制该方法),但我是希望有人可能碰巧已经知道答案并节省我一些时间,因为 TextBlock 控件只是......疯狂。

所以 - 我可以扩展这个 TextBlock 以便我可以按我想要的方式描边文本吗?


编辑 1:

为清楚起见,似乎有人对我要做什么有误解——我不关心文本块的轮廓。我想概述 TEXT 本身。

像这样:

<TextBlock >
    <TextBlock.Effect>
        <DropShadowEffect ShadowDepth="0"
                    Color="Red"
                    Opacity="1"
                    BlurRadius="5"/>
    </TextBlock.Effect>
    Some text that we want outlined
</TextBlock>

使用DropShadowEffect模拟Glow/Outline效果。