gpt4 book ai didi

WPF DropShadowEffect 中断按钮中的文本

转载 作者:行者123 更新时间:2023-12-01 19:37:11 25 4
gpt4 key购买 nike

我已经为我的按钮定义了一种样式,其中包含使用阴影来增加深度。我在网上读到这有时会导致文本模糊,但可以在 WPF4 中使用以下方法解决:

TextOptions.TextFormattingMode="Display"

但是,我的按钮中的文本并不模糊,只是显示不正确,上面的代码没有改善显示效果。

带阴影: enter image description here

没有阴影:enter image description here

投影是在应用于按钮的样式中定义的。

<Style TargetType="Button" x:Key="RedButton">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="MinHeight" Value="25" />
<Setter Property="MinWidth" Value="70" />
<Setter Property="FontFamily" Value="Verdana" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border TextBlock.Foreground="{TemplateBinding Foreground}" x:Name="Border" CornerRadius="6" BorderThickness="1">
<Border.BorderBrush>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="{StaticResource DarkRedColor}" Offset="1.0" />
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Border.BorderBrush>
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="{StaticResource LightRedColor}" Offset="0.5" />
<GradientStop Color="{StaticResource DarkRedColor}" Offset="1" />
</LinearGradientBrush>
</Border.Background>
<Border.Effect>
<DropShadowEffect Color="Black" Opacity=".50" ShadowDepth="4" RenderingBias="Quality" />
</Border.Effect>.....

最佳答案

认为是因为 DropShadowEffect试图应用于所有 child ,我想这就是 ContentPresenter 的地方在Style

试试这个:

<Style x:Key="RedButton"
TargetType="Button">
...
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Border x:Name="Border"
BorderThickness="1"
CornerRadius="6"
TextBlock.Foreground="{TemplateBinding Foreground}">
<Border.BorderBrush>
<LinearGradientBrush StartPoint="0,0"
EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Offset="1.0"
Color="{StaticResource DarkRedColor}" />
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Border.BorderBrush>
<Border.Background>
<LinearGradientBrush StartPoint="0.5,0"
EndPoint="0.5,1">
<GradientStop Offset="0.5"
Color="{StaticResource LightRedColor}" />
<GradientStop Offset="1"
Color="{StaticResource DarkRedColor}" />
</LinearGradientBrush>
</Border.Background>
<Border.Effect>
<DropShadowEffect Opacity=".50"
RenderingBias="Quality"
ShadowDepth="4"
Color="Black" />
</Border.Effect>
</Border>
<Border BorderThickness="1"
CornerRadius="6"
TextBlock.Foreground="{TemplateBinding Foreground}">
<ContentPresenter />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

关于WPF DropShadowEffect 中断按钮中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16056604/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com