1

I put the two following Style in App.xaml of my WPF application. If I change the FontSize to a different value, the Designer of Visual Studio 2019 shows all the controls with the specified FontSize. If I run the app, the controls show a FontSize of 12.

<Application x:Class="testapp.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:testapp"
         StartupUri="MainWindow.xaml">


<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="View/Themes/ButtonStyle.xaml"/>
            <ResourceDictionary Source="View/Themes/CheckBoxStyle.xaml"/>
            <ResourceDictionary Source="View/Themes/ComboBoxStyle.xaml"/>
            <ResourceDictionary Source="View/Themes/DataGridStyle.xaml"/>
        </ResourceDictionary.MergedDictionaries>
        <Style TargetType="{x:Type Page}">
            <Setter Property="FontSize" Value="18" />
        </Style>
        <Style TargetType="{x:Type Window}">
            <Setter Property="FontSize" Value="18" />
        </Style>
    </ResourceDictionary> 
</Application.Resources>

enter image description here

Mister 832
  • 1,177
  • 1
  • 15
  • 34

1 Answers1

1

If you research a bit, there has been an issue on this going back ten+ years on windows/pages. In design time the designer will get the style, but due to the Page/Window being derived types, during runtime they won't.

The fix (or workaround depending one one's viewpoint) is to name the style in app.xaml with x:key such as (page only shown for brevity):

<Style x:Key="pStyle" TargetType="{x:Type Page}">
    <Setter Property="FontSize" Value="18" />
</Style>

and then set to the static resource style on each page/window such as below

Style="{StaticResource pStyle}"

such as:

<Page x:Class="WPFStack.ListBox.ListViewQuestion"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:WPFStack.ListBox"
      mc:Ignorable="d" 
      xmlns:model="clr-namespace:WPFStack.Model"
      d:DesignHeight="450" d:DesignWidth="800"
      Style="{StaticResource pStyle}"
      Title="ListViewQuestion">

See How to set default WPF Window Style in app.xaml

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
  • Thank you for the answer. I saw the old post, but was hoping for a fix/improvement in the meantime. – Mister 832 Dec 30 '20 at 14:40
  • I was wondering that too, whether it was to old...but I tested the scenario under VS and Blend and that somewhat suggested it wasn't related to the editors. Interesting situation. – ΩmegaMan Dec 30 '20 at 14:44