In this post, CodeNaked discusses how to change the TextFormattingModeProperty of the application. This solves my problem (see below) perfectly in .Net 4. However my production application is in .Net 3.5 which doesn't have that property at all. How do I accomplish the same thing in .Net 3.5?
My root problem:
I have a winforms application based in .Net 3.5 that has some WPF controls on certain screens. When the Windows DPI setting is set to 150% (not 120%), scaling occurs as expected. However, as soon as a WPF control is created, the scaling is set back to 100% for all windows. I would like the scaling to remain unchanged.
I created a test application to demonstrate. By default it opens a winform that has a button that will open another winform with a wpf control. Left unchanged, opening the second form will cause scaling to revert to 100%. However, if line 11 in Form1.vb is uncommented, scaling will continue to occur correctly when the second form is opened.
Dim newApp As New App() 'Uncomment to fix automatic scaling
Class App:
Imports System.Windows
Imports System.Windows.Media
Partial Public Class App
Inherits Application
Public Sub App()
TextOptions.TextFormattingModeProperty.OverrideMetadata(GetType(Window), New FrameworkPropertyMetadata(TextFormattingMode.Display, FrameworkPropertyMetadataOptions.AffectsMeasure Or FrameworkPropertyMetadataOptions.AffectsRender Or FrameworkPropertyMetadataOptions.Inherits))
End Sub
End Class