【问题标题】:WPF DropShadowEffect Breaking Text in ButtonWPF DropShadowEffect 打破按钮中的文本
【发布时间】:2013-04-10 00:18:08
【问题描述】:

我已经为我的按钮定义了一种样式,其中包含使用阴影来增加深度。 我在网上看到这有时会导致文本模糊,但可以在 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>.....

【问题讨论】:

    标签: wpf xaml button user-interface dropshadow


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多