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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:41:39+00:00 2026-05-15T18:41:39+00:00

We are wiring up our views and view models externally meaning we have the

  • 0

We are wiring up our views and view models “externally” meaning we have the following type of code somewhere:

var viewModel = new MyViewModel();
var view = Application.Current.FindResource("MyView") as UserControl;
view.DataContext = viewModel;

That is a paraphrase of sorts. We do this so that the dll containing all of the views can be switched out at run-time. So long as the dll defines a resource named “MyView” that points to the usercontrol MyView all is good.

My concern is just to make sure that FindResource does not suffer or is inferior in a meaningful way to just doing the following:

var view = new MyView();

This could be replaced with IoC. (We don’t allow the user to switch which view DLL is used. It is determined when the app starts.)

One thing with FindResource I have found is that you may have to use x:Shared="False" or else WPF will hand you back an existing instance and you must make sure it is “initalized” back to its original state.

Any thoughts?

  • 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-15T18:41:39+00:00Added an answer on May 15, 2026 at 6:41 pm

    Declaring UIElement instances as Resources is almost always a bad idea. You’ve already seen one of the major issues with doing it (and workaround). It’s also very easy to cause memory leaks because items in the App level Resources are instantiated at startup and stay there until the app is closed (unless you do more manual work to force them to clean up).

    Using templates is a much better solution and it should be very easy to convert from what you’re already doing. The template will instantiate new instances of its child elements as needed and inject them locally as if they were declared inline. Just wrap your existing UserControl declarations in DataTemplate elements and move the x:Key declarations. Then when you get to the code above (could also be done in XAML or possibly implicitly with DataType templates) do:

    var viewModel = new MyViewModel();
    var view = Application.Current.FindResource("MyView") as DataTemplate;
    var control = new ContentControl { Content = viewModel, ContentTemplate = view };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problems with wiring up datepicker The code for partial view @model System.DateTime @Html.TextBox(, Model.ToString(dd/MM/yy),
With NInject (preferably 2.0), what options do we have wrt wiring up our object
I've got the following code wiring a NHibernate ISession in Autofac for a ASP.NET
I have a question about wiring web server controls. From many of the examples
I am wiring my UserService type classes using spring's IOC. But what about my
A bit confused with wiring controllers, I need some help I create a new
I'm wiring the following method to my document.ready function. However, the myAutoCompleteURL.aspx URL is
We have code that loads SVG via Ajax and interacts via Javscript. The SVG
I'm trying to create a new annotation with which I'll do some runtime wiring,
Loose coupling is wonderful of course, but I have often wondered what overhead wiring

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.