7

我需要在标签上创建外发光效果并使其旋转一点(大约 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" />
4

3 回答 3

12
  1. 您可能想要使用较小的BlurRadius,将其设置为 100 将使效果接近于不可见。我建议10。
  2. 将 设置为RenderTransformOrigin您希望文本围绕旋转的点(0.5, 0.5表示围绕中心旋转)。
  3. 添加一个RotateTransform里面Label.RenderTransform

完整的代码应该接近这个:

<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>
于 2012-07-15T17:05:14.737 回答
1

这是您可以旋转标签的方式:

<Label>
  <Label.LayoutTransform>
    <RotateTransform Angle="20"/>
  </Label.LayoutTransform>
  <Label.Content>text</Label.Content>
</Label>
于 2012-07-15T17:05:23.920 回答
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>

它看起来如何

于 2019-05-17T15:10:33.767 回答