I'm looking for an effect similar to ---- or ----
. However, the code below is creating a strike through effect. I thought that setting Grid.ZIndex
would solve the issue, however it doesn't seem to be doing anything.
<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>
If I set a background to my TextBlock
control then all works fine. What I want, though, is to use the defau开发者_开发技巧lt gray background (e.g. not set a background at all).
How can I accomplish this?
It's better to use TextDecorations
<TextBlock>
<TextBlock.TextDecorations>
<TextDecoration Location="Strikethrough">
<TextDecoration.Pen>
<Pen Brush="Red" />
</TextDecoration.Pen>
</TextDecoration>
</TextBlock.TextDecorations>
Strike through
</TextBlock>
The solution was actually quite simple.
<Grid>
<TextBlock Text="or" FontSize="22" Height="34" HorizontalAlignment="Center" Background="{Binding Path=Background, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" />
<Line Stretch="Fill" Stroke="Black" X1="1" Margin="0 4 0 -1" SnapsToDevicePixels="True" Height="34" Grid.ZIndex="-99" />
</Grid>
精彩评论