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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:14:47+00:00 2026-06-18T09:14:47+00:00

I have a View : internal partial class StartWindow : Window { public StartWindow()

  • 0

I have a View:

internal partial class StartWindow : Window
{
    public StartWindow()
    {
        InitializeComponent();
    }

    [ImportingConstructor]
    public StartWindow(IStartWindowViewModel viewModel)
        :this()
    {
        ViewModel = viewModel;
    }

    public IStartWindowViewModel ViewModel { get; private set; }
}

And an appropriate ViewModel:

    [Export]
    internal class StartWindowViewModel : IStartWindowViewModel
    {
        public IEnumerable<Customer> Customers { get; set; }
    }

UPD(based on @Blachshma answer):
I can`t inject StartWindow view into my App using code:

public class App
{
     [ImportingConstructor]
     public App(StartWindow window)
     {
          // Do whatever you need
     }

because parameterless constructor need by App.g.cs:

internal partial class App : System.Windows.Application {

        /// <summary>
        /// Application Entry Point.
        /// </summary>
        [System.STAThreadAttribute()]
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
        public static void Main() {
            TransparentNotification.App app = new TransparentNotification.App();
            app.Run();
        }
    }

Now, I want to instantiate in app.cs my view via constructor injection. What should I do for it?

Also, Im looking for best practices forMEF/MVVM` solutions (some sample code for this would be a great idea).

p.s. .NET 4.5

  • 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-06-18T09:14:48+00:00Added an answer on June 18, 2026 at 9:14 am

    If you want to get an instance of the view using MEF, you first of all need to Export the view.
    So add the [Export] attribute to your StartWindow class:

    [Export]
    partial class StartWindow : Window
    {
      ...
    

    Now, in your App class use ImportingConstrutor to get the instance:

    public class App
    {
         [ImportingConstructor]
         public App(StartWindow window)
         {
              // Do whatever you need
         }
    

    Regarding good articles on MVVM, I recommend Josh Smith’s blog

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

Sidebar

Related Questions

i have this in my partial view: <script type=text/javascript> var jqxhr = $.getJSON(<%= Url.Action(GetTrainingModulePoints
I have a UserControl with a ViewModel class as DataContext: XAML <UserControl x:Class=DotfuscatorTest.UserControl.View.UserControlView xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
I have successfully been using the eclipse Indigo internal browser to view my web
I have forms posting data from instances of a particular abstract class: public abstract
I have a View base iphone application I add a NSObject class AddNewContact and
I have a view_mine_and_others.php file that outputs this html <div class=rec id=1> <div class=val>343</div>
I am have a custom keyboard app, and I get this LogCat output about
I have an activity: public class Notepadv1 extends ListActivity { public static final int
I have view on which I defined a custom tagName. I need to be
i have view like 'home/details/5', it can be access by anonymous user. but there

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.