- 1 year ago
Is there a way to disable scaling for all the WPF application even if windows has some scale per monitor or system-wide scale?
Yes, you can disable scaling for WPF applications by setting the EnableDpiAwareness
property to False
in the application manifest.
Here's how you can do it:
Open your WPF application project in Visual Studio.
Right-click on your project in the Solution Explorer and select "Properties".
In the project properties window, go to the "Application" tab.
Click on the "View Application Events" button. This will open the code-behind file for the application events.
In the
Application.xaml.vb
orApplication.xaml.cs
file, locate theOnStartup
event handler.Inside the
OnStartup
event handler, add the following code to disable scaling:csharpprotected override void OnStartup(StartupEventArgs e)
{
// Disable scaling for the application
System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
System.Windows.Forms.Application.Run(new YourMainWindow());
}
Replace
YourMainWindow
with the actual class name of your main window.Save the changes and build your application.
By disabling scaling in the application manifest, your WPF application will not be affected by the system-wide scale or per-monitor scaling settings of Windows.
Note that disabling scaling can result in your application appearing smaller or larger on high-DPI displays. It's important to thoroughly test your application on different display configurations to ensure that it looks and functions correctly.