【问题标题】:Dropshadow appearing around textblock itself instead of the individual text characters阴影出现在文本块本身而不是单个文本字符周围
【发布时间】:2013-05-13 15:59:34
【问题描述】:

在我的代码中,我在 SurfaceListBox 中创建了一个 DataTemplate。我向堆栈面板以及堆栈面板中的文本块添加了阴影。当我运行它时,文本块上的阴影出现在文本块 UI 元素本身上,而不是文本的单个字符上。我想知道为什么会发生这种情况以及是否有办法解决它,所以文本上确实会出现阴影。

<DataTemplate>
    <StackPanel Background="WhiteSmoke" Height="190" Width="190">      
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="140"/>
                <RowDefinition Height="50"/>
            </Grid.RowDefinitions>
            <Image VerticalAlignment="Top" HorizontalAlignment="Center" Height="140" Width="140" Stretch="Fill" Source="{Binding ImagePath}" />
            <TextBlock Grid.Row="1" Text="{Binding Name}" Background="#9FCC19" Width="190" Height="50" TextAlignment="Center" VerticalAlignment="Center" Foreground="WhiteSmoke" 
                                               FontFamily="Segoe" FontSize="20" >
                 <TextBlock.Effect>
                     <DropShadowEffect ShadowDepth="2" RenderingBias="Performance"/>
                 </TextBlock.Effect>
             </TextBlock>
         </Grid>
         <StackPanel.Effect>
             <DropShadowEffect ShadowDepth="2"/>
         </StackPanel.Effect>
    </StackPanel>
</DataTemplate>

【问题讨论】:

    标签: wpf xaml


    【解决方案1】:

    你需要去掉 TextBlock 的背景颜色。你可以在 TextBlock 后面放一个 Rectangle 来达到同样的效果。

    <DataTemplate>
        <StackPanel Background="WhiteSmoke" Height="190" Width="190">      
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="140"/>
                    <RowDefinition Height="50"/>
                </Grid.RowDefinitions>
                <Image VerticalAlignment="Top" HorizontalAlignment="Center" Height="140" Width="140" Stretch="Fill" Source="{Binding ImagePath}" />
                <Rectangle Fill="#9FCC19" Grid.Row="1" Width="190" Height="50"/>
                <TextBlock Grid.Row="1" Text="{Binding Name}" Width="190" Height="50" TextAlignment="Center" VerticalAlignment="Center" Foreground="WhiteSmoke" 
                                               FontFamily="Segoe" FontSize="20" >
                     <TextBlock.Effect>
                         <DropShadowEffect ShadowDepth="2" RenderingBias="Performance"/>
                     </TextBlock.Effect>
                 </TextBlock>
             </Grid>
             <StackPanel.Effect>
                 <DropShadowEffect ShadowDepth="2"/>
             </StackPanel.Effect>
        </StackPanel>
    </DataTemplate>
    

    【讨论】:

    • 是的,就是这样。感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-24
    • 1970-01-01
    • 2011-09-18
    • 1970-01-01
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多