1

I have a problems with styles for my WPF application. Some users apply Classic Widows Theme and ActualHeight of a text block with same properties(font size, margin, padding) is different depending on which them is used.
For example Height of TextBlock with FontSize=15 using aero theme is 20 and in classic is 18.

How could I avoid such behaviour?

Ruslan F.
  • 5,498
  • 3
  • 23
  • 42

1 Answers1

3

The default styles for the built-in controls do look different depending on which Windows theme that is applied.

If you want to avoid this you could force your application to always use a specific theme by adding the corresponding theme's resource dictionary to your App.xaml file:

<Application x:Class="WpfApplication1.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:local="clr-namespace:WpfApplication1" 
             StartupUri="MainWindow.xaml" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             d1p1:Ignorable="d" xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/PresentationFramework.Aero, Version=3.0.0.0,
 Culture=neutral, PublicKeyToken=31bf3856ad364e35,
 ProcessorArchitecture=MSIL;component/themes/aero.normalcolor.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

Don't forget to add a reference to the corresponding assembly (Project->Add Reference->Assemblies->Framework in Visual Studio), for example PresentationFramework.Aero.dll if you decide to use the Aero theme.

Windows 7 theme for WPF?

How to Actually Change the System Theme in WPF: http://northhorizon.net/2010/how-to-actually-change-the-system-theme-in-wpf/

Community
  • 1
  • 1
mm8
  • 163,881
  • 10
  • 57
  • 88