如何在wpf中将Drop Shadow,Inner Shadow,Gradient Overlay效果应用于TextBlock

时间:2013-10-17 06:28:04

标签: wpf wpf-controls

我对我的PSD有以下效果: -

==============投影=============

-Blend Mode: - Multiply

- 颜色: - 黑色

-Opacity: - 50%

-Angel: - 90

=========内阴影================

-Blend Mode: - Normal

- 颜色: - 白色

-Opacity: - 62%

-Angel: - 120

=======渐变叠加===============

-Blend Mode: - Normal

-Opacity: - 100%

-Angel: - 90

- 开始颜色: - #8a8a8a

- 结束颜色: - #ffffff

以下是来自psd的图片 enter image description here

如何申请Textblack我已应用以下代码: -

<TextBlock x:Name="lblTitle" Margin="5" Foreground="#FFFFFFFF" FontWeight="Bold" FontSize="20" FontFamily="Arial Bold"
                            TextOptions.TextFormattingMode="Display"  TextAlignment="Left" TextWrapping="Wrap" Text="Tournament: $3 + $0.30 KO Sit and Go">
                                    <TextBlock.Effect>
                                        <DropShadowEffect Color="Black" Opacity="50" Direction="-90" RenderingBias="Quality" ShadowDepth="2" >

 </DropShadowEffect>
    </TextBlock.Effect>
     </TextBlock>

2 个答案:

答案 0 :(得分:3)

Hi we can add the  Inner Shadow as follows

<Grid Height="100" Width="600" Margin="100,100,100,100">
        <Border Background="LightGray" BorderBrush="DarkGray" 
           BorderThickness="1" ClipToBounds="True">
            <Border Background="Transparent" BorderBrush="Black" 
              BorderThickness="1" Margin="-2">
                <Border.Effect>
                    <DropShadowEffect ShadowDepth="0" BlurRadius="10">
                    </DropShadowEffect>
                </Border.Effect>

            <TextBlock x:Name="lblTitle" Margin="5" Foreground="#FFFFFFFF" FontWeight="Bold" FontSize="20" FontFamily="Arial Bold"
        TextOptions.TextFormattingMode="Display"  TextAlignment="Left" TextWrapping="Wrap" Text="Tournament: $3 + $0.30 KO Sit and Go">
            <TextBlock.Effect>
                <DropShadowEffect Color="Black" Opacity="50" Direction="-90" RenderingBias="Quality" ShadowDepth="2" >

                </DropShadowEffect>

            </TextBlock.Effect>

        </TextBlock>
            </Border>
        </Border> 

    </Grid>

答案 1 :(得分:1)

    Hi  this may help you in adding inner shadow and gradient overlay effect to TextBlock                                                                                          


  <Grid Height="100" Width="600" Margin="100,100,100,100">
        <Border Background="LightGray" BorderBrush="DarkGray" 
           BorderThickness="1" ClipToBounds="True">
            <Border Background="Transparent" BorderBrush="Black" 
              BorderThickness="1" Margin="-2">
                <Border.Effect>
                    <DropShadowEffect ShadowDepth="0" BlurRadius="10">
                    </DropShadowEffect>
                </Border.Effect>

            <TextBlock x:Name="lblTitle" Margin="5"  FontWeight="Bold" FontSize="20" FontFamily="Arial Bold"
        TextOptions.TextFormattingMode="Display"  TextAlignment="Left" TextWrapping="Wrap" Text="Tournament: $3 + $0.30 KO Sit and Go">
                    <TextBlock.Foreground>
                        <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                            <GradientStop Color="White" Offset="0"/>
                            <GradientStop x:Name="WhiteOffset" Color="White" Offset="1"/>
                            <GradientStop x:Name="GrayOffset" Color="Gray" Offset="1"/>
                        </LinearGradientBrush>
                    </TextBlock.Foreground>
                    <TextBlock.Triggers>
                        <EventTrigger RoutedEvent="Loaded">
                            <BeginStoryboard>
                                <Storyboard Storyboard.TargetProperty="Offset" Duration="0:0:1" RepeatBehavior="Forever">
                                    <DoubleAnimation Storyboard.TargetName="WhiteOffset" From="0" To="1" />
                                    <DoubleAnimation Storyboard.TargetName="GrayOffset" From="0" To="1" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </TextBlock.Triggers>
                    <TextBlock.Effect>
                <DropShadowEffect Color="Black" Opacity="50" Direction="-90" RenderingBias="Quality" ShadowDepth="2" >

                </DropShadowEffect>

            </TextBlock.Effect>

        </TextBlock>
            </Border>
        </Border> 

    </Grid>