title: DPI Scaling in .Net 3.5 in Mixed WinForms and WPF Application
body: <p>In <a href="https://stackoverflow.com/questions/5376885/wpf-how-to-enable-textformattingmode-display-for-all-controls-in-the-applica">this post</a>, 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?</p>
  
  <p>My root problem:</p>
  
  <p>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.</p>
  
  <p>I created a <a href="http://www.mediafire.com/download/5ybkk59oz5gd0ev/AutoSizeTest.zip" rel="nofollow noreferrer">test application</a> 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.</p>
  
  <pre><code>Dim newApp As New App() 'Uncomment to fix automatic scaling
  </code></pre>
  
  <p>Class App:</p>
  
  <pre><code>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
  </code></pre>