2013-05-11 97 views
1

我有一個WPF窗體具有TextBoxes和DatePickers。 DatePicker文本框的字體真的很模糊,因爲我在樣式上放置了陰影效果。最初,所有控件都具有明確的陰影效果作爲樣式的一部分,但我通過從控件中刪除陰影效果並將其移至具有相同陰影的矩形來解決此問題。WPF修復模糊DataPicker文本框有陰影

然後我將矩形直接放在文本框的後面 - 我仍然有視覺效果,疊加控件中的字體看起來很棒。

<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的文本框雲裏霧裏的字體相同的問題,因爲陰影效果還是直接控制。

enter image description here

我沒有一個datepicker的風格,但我確實有DatePickerTextBox,這是其中的效果來自於一種風格。

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

我不知道該怎麼辦,是按照我以前的去除效果的圖案,具有相同效果的創建矩形,並把它背後的文本框的DatePicker所以它的同尺寸等我需要XAML的一點幫助才能這樣做。

任何人都可以提供任何建議嗎?

謝謝!

+1

有你的'DatePickerTextBox'風格嘗試'SnapsToDevicePixels' ,例如:'' – 2013-05-11 02:45:37

+0

由於這是文本,我會考慮修改文本的ClearType屬性:http://msdn.microsoft.com/en-us /library/ms749295.aspx – Xcalibur37 2013-05-11 14:27:04

+0

這兩個建議(SnapsToDevicePixels和RenderOptions.ClearTypeHint)都沒有改變任何東西。我有一個解決方案,我只是不知道如何在XAML中進行設置。 – cardinalPilot 2013-05-11 14:42:29

回答

0

因爲關於TextFormattingMode的知識確實需要傳播,所以我決定發佈以下內容 - 即使它奇怪地對DatePickerTextBox沒有幫助,但仍然很模糊。它可以防止你從TextBox後面的矩形拉出來的特技。

enter image description hereenter image description here

除非你有大,或轉換文字,總是在你最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>