外部辉光效果和旋转在WPF中的标签上

时间:2012-07-15 16:41:27

标签: c# wpf xaml

我需要在标签上创建外部发光效果并使其旋转一点(约20度)。我正在使用以下代码,但它不能按我希望的方式工作:

<Label Height="106" Margin="80,57,36,0" Name="lblHeading" FontSize="35">
    Brian's 15th Birthday Party
    <Label.Effect>
        <DropShadowEffect BlurRadius="100" ShadowDepth="0" Opacity="1" 
                          Color="White"/>
    </Label.Effect>
</Label>

是否可以在窗口的某处添加一些文字并为其添加外部发光效果和旋转?如果有人可以帮助我在标签上添加相同的效果或者在不使用标签控件的情况下以任何其他方式这样做,那将是很棒的。

我也尝试了以下内容,但它没有帮助。也许我不知道如何使用它,因为它只是导致错误:

<OuterGlowBitmapEffect GlowColor="Blue" GlowSize="30" Noise="1" Opacity="0.4" />

3 个答案:

答案 0 :(得分:9)

  1. 您可能希望使用较小的BlurRadius,将其设置为100会使效果接近隐形。我建议10。
  2. RenderTransformOrigin设置为您希望文本旋转的点(0.5, 0.5表示围绕中心旋转)。
  3. RotateTransform内添加Label.RenderTransform
  4. 完整的代码应该看起来很接近:

    <Label Height="106" Margin="80,57,36,0" Name="lblHeading" FontSize="35"
           RenderTransformOrigin="0.5, 0.5">
        Brian's 15th Birthday Party
        <Label.Effect>
            <DropShadowEffect BlurRadius="10" ShadowDepth="0" Opacity="1" 
                          Color="White"/>
        </Label.Effect>
        <Label.RenderTransform>
            <RotateTransform Angle="20"/>
        </Label.RenderTransform>
    </Label>
    

答案 1 :(得分:1)

这是您旋转标签的方法:

<Label>
  <Label.LayoutTransform>
    <RotateTransform Angle="20"/>
  </Label.LayoutTransform>
  <Label.Content>text</Label.Content>
</Label>

答案 2 :(得分:0)

这可以通过在ControlTemplate中进行修改来完成。

关键是使用两个ContentPresenter来显示您的文本,并将BlurEffect附加到一个ContentPresenter上。

代码:

<Label Content="TestContent" Foreground="White" FontSize="20">
    <Label.Template>
        <ControlTemplate TargetType="Label">
            <Border>
                <Grid>
                    <ContentPresenter TextBlock.Foreground="{TemplateBinding Foreground}"/>
                    <ContentPresenter TextBlock.Foreground="{TemplateBinding Foreground}">
                        <ContentPresenter.Effect>
                            <BlurEffect Radius="5"/>
                        </ContentPresenter.Effect>
                    </ContentPresenter>
                </Grid>
            </Border>
        </ControlTemplate>
    </Label.Template>
</Label>

How it looks

相关问题