在WPF中有效地在图像上显示文本? [英] Efficiently display text on image in WPF?
本文介绍了在WPF中有效地在图像上显示文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在图像上显示文本,使其始终可见(因为图像的颜色混合且难以预测)?
How to display text on an image, so it should always visible (because the image colors are mixed and unpredictable)?
我考虑了两个选择:
- 使文本边框为白色,而文本本身将为黑色
- 文字在图片上显示为负数
首选1st选项,因为它看起来更牢固.
The 1st option would be preferred since it looks more solid.
嵌入文字很简单:
<Grid>
<Image Source="{Binding ImageLink}" Width="110" />
<TextBlock Text="{Binding Description}"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
答案上的更新:
听起来不错,但不起作用.
Sounds like a great idea except it doesn't work.
我尝试了您的代码,结果如下:
I tried your code, and here are the results:
左图是当我将 Color
属性设置为 White
,并将 ShadowDepth
属性设置为 10
时.>
The left image is when I set the Color
property to White
and ShadowDepth
to 10
.
推荐答案
我做到了,它有帮助:
<Style x:Key="AnnotationStyle" TargetType="TextBlock">
<Setter Property="Background" Value="#70FFFFFF" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="TextWrapping" Value="Wrap"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#CCFFFFFF" />
</Trigger>
</Style.Triggers>
</Style>
....
<TextBlock ... Style="{StaticResource AnnotationStyle}"/>
这是它的样子:
Here is what it looks like:
这篇关于在WPF中有效地在图像上显示文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文