Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 609761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:36:03+00:00 2026-05-13T17:36:03+00:00

I would like to update the default Window style dynamically at runtime so I

  • 0

I would like to update the default Window style dynamically at runtime so I can change the FontSize and FontFamily dynamically at runtime. I found that Styles in your resource dictionary are sealed at runtime and cannot be changed, so I used the following method of updating the style:

<Style TargetType="{x:Type Window}">
    <Setter Property="FontFamily" Value="Arial"/>
    <Setter Property="FontSize" Value="12pt"/>
</Style>

With the following code:

Style newStyle = (Make a copy of the old style but with the FontSize and FontFamily changed)

// Remove and re-add the style to the ResourceDictionary.
this.Resources.Remove(typeof(Window));
this.Resources.Add(typeof(Window), newStyle);

// The style does not update unless you set it on each window.
foreach (Window window in Application.Current.Windows)
{
    window.Style = newStyle;
}

There are several problems with this approach and I have a few questions as to why things are the way they are.

  1. Why are styles sealed at runtime and is there a way of making them unsealed?
  2. When I re-add the new style, why is this not picked up by all of my windows? Why do I have to go and manually apply it to every window?
  3. Is there a better way?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:36:04+00:00Added an answer on May 13, 2026 at 5:36 pm

    I would probably tackle this with a “settings service” which exposes properties for the various settings, and fires INPC as you would for normal binding. Next up I’d change that style to be something like:

    <Style x:Key="MyWindowStyle">
        <Setter Property="FontFamily" Value="{Binding Path=FontFamily, Source={StaticResource SettingsService}, FallbackValue=Arial}"/>
        <Setter Property="FontSize" Value="{Binding Path=FontSize, Source={StaticResource SettingsService}, FallbackValue=12}"/>
    </Style>
    

    With your “settings service” defined as a static resource:

    <services:SettingsService x:Key="SettingsService"/>
    

    Then in each window make sure the style is set as a DynamicResource:

    <Window Style="{DynamicResource MyWindowStyle}" .... >
    

    There is often a lot of misunderstanding around the differences between Static and Dynamic resources, but the basic difference is Static is a “one time” setting whereas Dynamic will update the settings if the resource changes.

    Now if you set those properties in your “settings service” they will fire INPC, which will update the Style, which the DynamicResource will pick up on and alter the Window properties accordingly.

    Seems like a lot of work, but it gives you some nice flexibility, and all the “heavy lifting” is done purely using Bindings. We use a similar technique on a project I’m working on at the moment so when a user chooses a fill/stroke colour the various tools in the toolbar update to reflect the new values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 378k
  • Answers 378k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There's a proppage.dll and an x64/proppage.dll and you'll need to… May 14, 2026 at 9:12 pm
  • Editorial Team
    Editorial Team added an answer You will have to assign a key to the command… May 14, 2026 at 9:12 pm
  • Editorial Team
    Editorial Team added an answer You can do something like this: $(window).load(function() { $(".image p.caption").each(function()… May 14, 2026 at 9:12 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.