WPF - Styles declared in Resource Dictionary not getting applied

478 views Asked by At

I have added the following styles in App.xml file of WPF application under Application.Resources tag and these styles are getting applied to the controls.

<Style TargetType="{x:Type TextBlock}">
  <Setter Property="FontSize" Value="16" />
  <Setter Property="FontFamily" Value="Calibri" />
</Style>
<Style TargetType="{x:Type Control}" x:Key="fontStyling">
  <Setter Property="FontSize" Value="16" />
  <Setter Property="FontFamily" Value="Calibri" />
</Style>
<Style TargetType="{x:Type Label}" BasedOn="{StaticResource fontStyling}" />
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource fontStyling}" />

Now, i have created a "Resource Dictionary" file, moved the above styles to Resource dictionary file and accessed the "Resource Dictionary" file in the App.XAML file using merged dictionaries

<ResourceDictionary x:Key="GlobalSettingsDictionary">
  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="ResourceDictionaries/GlobalSettings.xaml" />
  </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

When i run the WPF application then the Styles in the resource dictionary are not getting applied to the controls present in the Main Window. When i use the same styles in App.xaml file then they are getting applied

Am i missing anything? Can you please suggest on what needs to be done to get the styles defined in the Resource dictionary are applied to the controls in the MainWindow.xaml?

0

There are 0 answers