3

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

TextOptions.TextFormattingMode="Display"

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

带阴影: 在此处输入图像描述

没有阴影:在此处输入图像描述

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

<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>.....
4

1 回答 1

1

认为这是因为DropShadowEffect试图适用于所有孩子,我猜这ContentPresenterStyle

尝试这个:

<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>
于 2013-04-17T09:52:12.843 回答