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

  • Home
  • SEARCH
  • 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 9221999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:42:39+00:00 2026-06-18T03:42:39+00:00

As I understand it, when I bind my ViewModel to my View, it is

  • 0

As I understand it, when I bind my ViewModel to my View, it is done via the DataContext. Something like

   <Grid.Resources>
        <myData:MyVM x:Key="Vm" />
    </Grid.Resources>
    <Grid.DataContext>
        <Binding Source="{StaticResource Vm}"></Binding>
    </Grid.DataContext>

My understanding of how the ViewModel is populated is the View calls the ViewModel (via binding), and the ViewModel talks to the Model and does what ever it needs to do to get itself (ViewModel) into a desired state.

So, what happens if your “Model” is created by the UI? My model is a parameter on my MainWindow Constructor.

So, my View (MainWindow) is

public MainWindow(MyObject myObject)
    {
          InitializeComponent();
    }

My ViewModel is

 public class ViewModel 
{
    #region properties

    private MyObject myList;
    public MyObject MyList
    {
        get; set ;
    }

    #region Constructors

    public ViewModel ()
    {

    }

    public ViewModel (MyObject myObject)
    {
        this.myObject= myObject;
    }        
}

Now, when my application runs up, (and I’m sure I’m using the wrong words here) how do I ‘inject’ my parameter into the ViewModel? Or do we feel there is a better approach?

EDIT

To explain what I’m trying to achieve may help. My program performs some tasks and creates a log. The log is stored in memory. At the end of my programs processes, the log is shown on screen. This is why I’m passing the object into the constructor.

  • 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-18T03:42:41+00:00Added an answer on June 18, 2026 at 3:42 am

    Or do we feel there is a better approach?

    I’d rather see you bind your view to your view-model. If you are going to follow the MVVM pattern, then this is one way to do it. Now, I can’t be certain if you’re using dependency injection, but you mention “inject” in your question, so I’ll assume you are. Here’s a code sample:

    SET THE DATACONTEXT OF YOUR VIEW TO YOUR VIEW-MODEL:

     public YourView(IUnityContainer container)
            {
                InitializeComponent();
                this.DataContext = container.Resolve<IYourViewModel>();
            }
    

    INJECT YOUR MODEL INTO YOUR VIEW-MODEL:

     private YourModel _yourModel;
    
     public YourViewModel(YourModel yourModel)        
            {
                _yourModel = yourModel;
                InitializeDelegateCommands();
            }
    

    So, now your view-model is bound to your view. All model interaction should be coordinated throught the view-model.

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

Sidebar

Related Questions

I am using the Model View ViewModel pattern in my WPF application. The DataContext
I think C++0x bind is much better, but I'd like to understand the old
I would like to bind the following key sequence C-x r l to a
I'm trying to understand how binding works between the view model and page controls
I don't understand, I have a toolbar with buttons bind to custom commands. Also
I understand I can create an enum like this: public enum MyEnum { ONE(1),
I understand what weak tables are. But I'd like to know where weak tables
Im struggling to understand the ViewModel part of the MVVM pattern . My current
I understand the basic bind syntax for Option with functional java as Option.some(2).bind(new F<Integer,Option<Integer>>(){
Can anyone show me some absolutely minimal ASP.NET code to understand Eval() and Bind()

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.