【发布时间】:2010-12-02 11:57:19
【问题描述】:
是否可以对 WPF 中的标签文本应用外斜面效果?
对于我来说,Glow 效果应该足够了:
【问题讨论】:
标签: .net wpf wpf-controls
是否可以对 WPF 中的标签文本应用外斜面效果?
对于我来说,Glow 效果应该足够了:
【问题讨论】:
标签: .net wpf wpf-controls
这是一种在文本上获得发光效果的方法。使用来自this link 的 OutlinedText 控件,它提供了 Stroke。
<local:OutlinedText FontSize="100"
Fill="Black"
Bold="True"
Stroke="White"
StrokeThickness="3"
Text="Glow">
<local:OutlinedText.Effect>
<DropShadowEffect ShadowDepth="0"
Color="White"
Opacity="1"
BlurRadius="12"/>
</local:OutlinedText.Effect>
</local:OutlinedText>
更新
这是我最接近斜面效果的方法,但效果不是很好。使用了this link的方法。
<Style x:Key="ContentControlStyle1" TargetType="{x:Type ContentControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContentControl}">
<Grid>
<TextBlock Name="Highlight" Foreground="#66FFFFFF" Text="{TemplateBinding Content}" />
<TextBlock Name="Shadow" Margin="0,4,0,0" Foreground="#CC000000" Text="{TemplateBinding Content}"/>
<ContentPresenter Margin="0,2,0,0"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ContentControl Style="{DynamicResource ContentControlStyle1}" FontSize="101" Foreground="DarkGray" Content="Bevel"/>
【讨论】:
我对这个“解决方案”不是特别满意:
<TextBlock Text="Hello World!" Foreground="Red">
<TextBlock.Effect>
<BlurEffect Radius="1" KernelType="Box" />
</TextBlock.Effect>
</TextBlock>
<TextBlock Text="Hello World!" />
另一种选择是制作自己的像素着色器,我不太擅长,所以我怕帮不了你:/
编辑:更好的解决方案,但仍然不是斜角。
<TextBlock Text="Hello World!">
<TextBlock.Effect>
<DropShadowEffect BlurRadius="2" Color="Red" Direction="0" ShadowDepth="0" />
</TextBlock.Effect>
</TextBlock>
【讨论】:
据我所知这是可行的:
<Label Content="Hi there!">
<Label.BitmapEffect>
<OuterGlowBitmapEffect/>
</Label.BitmapEffect>
</Label>
我没有在标签中测试过这个,但我已经在其他控件和形状中为我工作过,此外,请查看 IntelliSense 为您提供的所有效果列表:)
【讨论】:
<Label.BitmapEffect><OuterGlowBitmapEffect GlowColor="White" GlowSize="5"/></Label.BitmapEffect>没用.. (
BevelBitmapEffect,但是我没有实现将它应用于标签文本。
啊,好吧,我更了解你的问题了。
试试这样的:
<Grid>
<Grid.Resources>
<OuterGlowBitmapEffect GlowColor="Blue" GlowSize="5" x:key="Glow" />
</Grid.Resources>
<Label Content="Blah!" BitmapEffect="{StaticResource Glow}" />
</Grid>
我得到“废话!”带着蓝色的光芒。似乎是一个体面的工作,因为标签的内容不能设置两次。
希望有帮助!
编辑:除非您使用的是 Framework 3.5,否则这将不起作用,因为 BitmapEffect 已被弃用。 :(
【讨论】:
听从 Oggy 的建议:
<Label.Effect>
<DropShadowEffect BlurRadius="5"
Color="Red"
Opacity="1"
ShadowDepth="0" />
</Label.Effect>
【讨论】: