【问题标题】:WPF fixing fuzzy DataPicker text boxes that have drop shadowsWPF 修复了具有阴影的模糊 DatePicker 文本框
【发布时间】:2013-05-11 01:11:37
【问题描述】:

我有一个包含 TextBoxes 和 DatePickers 的 WPF 表单。 DatePicker 文本框字体非常模糊,因为我在样式上添加了阴影效果。最初,所有控件都具有作为样式的一部分的显式投影效果,但我通过从控件中删除投影效果并将其移动到具有相同投影的矩形来解决此问题。

然后我将 Rectangle 直接放在文本框的后面 - 我仍然有视觉效果,并且叠加控件中的字体看起来很棒。

<DropShadowEffect x:Key="dropShadow" Color="Gray" Opacity=".50" ShadowDepth="8" />

<Style x:Key="BackingRectangleStyle" TargetType="Rectangle">
  <Setter Property="Effect" Value="{StaticResource dropShadow}" />
</Style>

<Rectangle Grid.Row="1" Grid.Column="3" Style="{StaticResource BackingRectangleStyle}"/>
<TextBox Grid.Row="1" Grid.Column="3" ... />

但是,我对 DatePicker TextBoxes 的模糊字体也有同样的问题,因为投影效果仍然直接在控件上。

我没有 DatePicker 样式,但我有 DatePickerTextBox 的样式,这就是效果的来源。

<Style TargetType="{x:Type DatePickerTextBox}">
  <Setter Property="Effect" Value="{StaticResource dropShadow}" />
</Style>

我不知道该怎么做是按照我之前删除效果的模式,创建一个具有相同效果的 Rectangle 并将其放在 DatePicker TextBox 后面,使其大小相同,等等。我需要一点帮助在 XAML 上这样做。

谁能给我一些建议?

谢谢!

【问题讨论】:

  • 你试过SnapsToDevicePixelsDatePickerTextBox风格吗,例如:&lt;Setter Property="SnapsToDevicePixels" Value="True" /&gt;
  • 由于这是文本,我会考虑修改文本的 ClearType 属性:msdn.microsoft.com/en-us/library/ms749295.aspx
  • 这两个建议(SnapsToDevicePixels 和 RenderOptions.ClearTypeHint)都没有改变任何东西。我有一个解决方案,只是不知道如何在 XAML 中进行设置。

标签: wpf wpf-controls


【解决方案1】:

因为关于 TextFormattingMode 的知识确实需要传播,所以我决定发布以下内容 - 尽管奇怪的是它对 DatePickerTextBox 没有帮助,这仍然是模糊的。不过,它可以防止您使用TextBox 后面的矩形拉出的特技。

除非您有大文本或转换后的文本,否则请始终在最外面的 WPF 容器中使用 TextOptions.TextFormattingMode="Display"。 这是在 WPF 4.0 中引入的,我想默认的“理想”反映了早期版本,但这是一个多么令人难以置信的错误......

<Window x:Class="WpfApplication1.MainWindow" x:Name="MyWindow" 
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Height="300" Width="400"
            TextOptions.TextFormattingMode="Display"> <!-- Please notice the effect of this on font fuzzyness -->
    <Grid>
        <Grid.Resources>
            <DropShadowEffect x:Key="DropShadow" Color="Gray" Opacity=".5" ShadowDepth="8"/>
        </Grid.Resources>
        <TextBox Text="Really Sharp" HorizontalAlignment="Center" Padding="3" VerticalAlignment="Center" Effect="{StaticResource DropShadow}"/>
    </Grid>
</Window>

【讨论】:

    猜你喜欢
    • 2019-01-10
    • 2013-12-16
    • 2016-04-22
    • 1970-01-01
    • 2011-08-24
    • 1970-01-01
    • 2017-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多