如何通过类似效果实现罢工

gcs*_*cso 2 wpf xaml

我正在寻找类似的效果---- or ----.但是,下面的代码创建了一个通过效果.我认为这个设置Grid.ZIndex可以解决问题,但它似乎没有做任何事情.

<Grid>
    <TextBlock Text="or" FontSize="22" Height="34" Grid.ZIndex="2" HorizontalAlignment="Center" />
    <Line Stretch="Fill" Stroke="Black" X1="1" Margin="0 4 0 -1" SnapsToDevicePixels="True" Grid.ZIndex="1" Height="34" />
</Grid>
Run Code Online (Sandbox Code Playgroud)

如果我为我的TextBlock控件设置背景,那么一切正常.但我想要的是使用默认的灰色背景(例如,根本不设置背景).

我怎么能做到这一点?

Nav*_*ani 11

最好使用 TextDecorations

<TextBlock>
    <TextBlock.TextDecorations>
        <TextDecoration Location="Strikethrough">
            <TextDecoration.Pen>
                <Pen Brush="Red" />
            </TextDecoration.Pen>
        </TextDecoration>
    </TextBlock.TextDecorations>
    Strike through
</TextBlock>
Run Code Online (Sandbox Code Playgroud)