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 211635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:06:47+00:00 2026-05-11T18:06:47+00:00

I am attempting to use an MVVM-ish approach to my WPF development. I have

  • 0

I am attempting to use an MVVM-ish approach to my WPF development.

I have my logical view model classes under the ViewModel namespace, and I have matching styling for these view model classes under the View namespace.

For now I have my View information in ResourceDictionary XAML files, as DataTemplates and Styles, which are all merged into the single App.Resources ResourceDictionary in app.xaml.

However, I’m running into a sort of chicken/egg problem. I want there to be global styles that I use all over the place. For example, I want my own custom text style called MonkeyText which could be used in various stylings all over the place. I can’t just set this in the app.xaml file, because the resourcedictionarys that will want to use MonkeyText are included by that app.xaml file.

I guess if that’s impossible an alternative would be to use UserControls instead of mostly using DataTemplates to establish my views? I’m afraid that using UserControls would tie the VM and V parts too closely together.

  • 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-11T18:06:48+00:00Added an answer on May 11, 2026 at 6:06 pm

    WPF provides DynamicResources for just this reason. StaticResources – which most resemble ‘traditional’ references in programming – have just the problem you encountered; they need to be defined and loaded prior to the point that a style is parsed. DynamicResources, on the other hand, do not need to be defined prior to the point they are used – indeed, you can even create them on the fly. WPF takes care of ensuring that DynamicResources are automatically loaded by all of the styles that reference them once they are actually loaded.

    Using DynamicResources is straightforward. When you create your MonkeyText style, create it as you normally would:

    <Style TargetType="TextBlock" x:Key="MonkeyText">
        <Setter Property="TextAlignment" Value="Center"/>
        <!-- etc. -->
    </Style>
    

    And then refer to it from elsewhere using a DynamicResource:

    <TextBlock Text="Hello, World!" Style="{DynamicResource MonkeyText}"/>
    

    If, for any reason, WPF cannot resolve your DynamicResource, it will fail silently without any exception thrown (StaticResources do throw exceptions when the cannot be resolved). It will, however, print a debug message when this happens – so keep an eye on the Output window in Visual Studio.

    Since DynamicResources work with resources that are loaded at any point in any order, you can structure your resource dictionaries any way you like – so putting them in with your other View styles and merging them in via the single App.Resources ResourceDictionary in app.xaml will work fine.

    More details on DynamicResources can be found in the MSDN docs for WPF.

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

Sidebar

Related Questions

attempting to use this railscast as a guide: http://railscasts.com/episodes/197-nested-model-form-part-2?view=asciicast and running into this error:
I'm attempting to use TPH mapping for the following classes. Ignore that there's only
I'm attempting to use Wix to create a database during install. I have my
I'm attempting to use groovyPageRenderer.render() to render a temple with a model, so that
I am attempting use Java Pathfinder and I have pathfinder working. import gov.nasa.jpf.jvm.Verify; user.java:2:
While attempting to use the CopyFile() function I have encountered a strange error. It
I'm attempting to use this approach, described by Marco Arment, for checking if a
I am using WPF, and attempting to follow the MVVM pattern. Our team has
Attempting to use the data series from this example no longer passes the JSONLint
Attempting to use XStream's JavaBeanConverter and running into an issue. Most likely I'm missng

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.