question

MERUNKUMARMAITY-4120 avatar image
0 Votes"
MERUNKUMARMAITY-4120 asked MERUNKUMARMAITY-4120 commented

DpiDecorator cause blurry text in my WPF application?

Hi there, I developing a WPF application where I use a Dpi Decorator class to adjust my WPF application according to any screen size. All of my application are perfectly working in any resolution except the text written on it. The text are became blurry and not render perfectly as I wish. I use SnapToDevice Pixel, Use Layout rendering, Text formatting mode = grey scale etc but none of them working pefectly.

Why I am telling the Dpi decorator cause the issue? because as soon as I remove the class from my application, my text looks perfectly.

Here is the Dpi Decorator class which I paste in the Window load event :

  public class DpiDecorator : Decorator
      {
          public DpiDecorator()
          {
              this.Loaded += (s, e) =>
              {
                  System.Windows.Media.Matrix m = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice;
                  ScaleTransform dpiTransform = new ScaleTransform(1 / m.M11, 1 / m.M22);
                  if (dpiTransform.CanFreeze)
                      dpiTransform.Freeze();
                  this.LayoutTransform = dpiTransform;
              };
          }
      }


And I use this :

 <local:DpiDecorator>
          <Grid Name="MainGrid" Background="#282828">
             <!--Your Controls-->
          </Grid>
      </local:DpiDecorator>


Here is my MainWindow.xaml code :

 <Window x:Class="WpfApp1.MainWindow"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:local="clr-namespace:WpfApp1"
         mc:Ignorable="d"
         AllowsTransparency="False"
         WindowStyle="None"
         MouseLeftButtonDown="Window_MouseLeftButtonDown"        
         Title="MainWindow"
         x:Name="LayoutRoot"
         ResizeMode="CanResize"
         Loaded="Window_Loaded"
         Height="547.4" Width="1024"
         >
     <local:DpiDecorator>
     <Grid  Background="#282828"    >
         <Grid.RowDefinitions>
             <RowDefinition Height="Auto"/>
             <RowDefinition Height="*"/>
             <RowDefinition Height="Auto"/>
         </Grid.RowDefinitions>
             <DockPanel x:Name="xp" Grid.Row="0" LastChildFill="False" Background="#282828">              
                 <Button
     Style="{StaticResource RoundCorner}"
         x:Name="BtnSettings" Width="90" HorizontalAlignment="Left" Margin="200,14,0,0" Height="30" DockPanel.Dock="Left"
      VerticalAlignment="Top"  UseLayoutRounding="True"  RenderOptions.ClearTypeHint="Enabled"  RenderOptions.BitmapScalingMode="NearestNeighbor"   SnapsToDevicePixels="True"        
                                     >
                     <Button.Content >
                         <TextBlock  FontSize="12" FontFamily="Segoe UI" UseLayoutRounding="True" SnapsToDevicePixels="True" RenderOptions.BitmapScalingMode="HighQuality"  TextOptions.TextFormattingMode="Display" Margin="0,-2,0,0" TextOptions.TextRenderingMode="ClearType" >                           
                     Settings
                         </TextBlock>                      
                     </Button.Content>
                 </Button>
             </DockPanel>
     </Grid>
     </local:DpiDecorator>
 </Window>

As you know in any application text are the heart of any application design. Can I use Glyph to overcome this issue.

dotnet-csharpwindows-wpf
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@MERUNKUMARMAITY-4120
On a device where fonts are blurry, are fonts in other apps, such as Office, blurry? Why do you want to use Glyphs to handle the blurry text? Could you show me the reason?

0 Votes 0 ·

No, in other applications fonts are not blurry. This blurry text is only a issue in my WPF application. This issue comes when I use the Dpi Decorator to my application. The issue gone if I remove the DPI Decorator from my application. But the Dpi Decorator is the heart of my application because by using this class I can adjust my application UI to different screen resolution.

Please give me a solution. That's why I think glyph is a solution. though I not using glyph previously.

0 Votes 0 ·

@MERUNKUMARMAITY-4120
Could you use Calibri to replace Segoe UI for FontFamily to try? Where do you know that Glyph is a solution? Could you show me the related link? By the way, what is the platform that your project target?

1 Vote 1 ·
Show more comments

0 Answers