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.