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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:11:00+00:00 2026-06-13T20:11:00+00:00

Recently I’m developing my first project using MVVM concept (I use WPF ). I’ve

  • 0

Recently I’m developing my first project using MVVM concept (I use WPF). I’ve read many tutorials (ia. famous J.Smith’s one) about MVVM before I started writing a code. Everything I’ve read had been clear until I started to code…

The problem is simple: in View layer I have a form with TextBoxes. Let’s say a few TextBoxes, ie.: Name, Surname, Phone number. When user fills all of them and clicks OK-button, I want to add new person (with specified personal details) to my local Database (I use Entity Framework as a ORM).

To do this I need to write something like this:

<Button Name="MyButton" Command="MyRelayCommandWhichNeedsAllOfTheTextboxes" Content="OK" />

Using CommandParameter I can pass one object from View to ViewModel. There are many textboxes so it’s probably not a good idea.

From XAML I can assign to CommandParameter whole form which needs to be filled by user. But then, inside ViewModel, I need to know all textboxes’ names. The main assumption in MVVM is that all the layers (View, ViewModel and Model) have to be independent.

What’s the best solution? How can I pass input data from form to ViewModel?

  • 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-13T20:11:01+00:00Added an answer on June 13, 2026 at 8:11 pm

    I would suggest having the relay command as part of your View Model — that way, when the command gets triggered, you’ll have access to all the properties you need.

    XAML:

    <Button Name="SurnameTextBox" Text="{Binding Surname,Mode=TwoWay}" />
    <Button Name="MyButton" Command="{Binding MyRelayCommand}" Content="OK" />
    

    View Model:

    public class MyViewModel : INotifyPropertyChanged
    {
        // (note, raise property changed on the setter
        public string Surname { get; set; }
    
        public ICommand MyRelayCommand { get; set; }
    
        public MyViewModel
        {
            // set the command callback here
            MyRelayCommand = new RelayCommand(OKCommandHandler); 
        }
    
        private void OKCommandHandler(object parameter)
        {
            // save the record here using Surname, etc
            // (note that you don't even need to use parameter, so you can just ignore it)
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently our WPF/Entity Framework 4.0 application has become unstable after we began using backgroundworkers
Recently I was asked to develop an app, which basically is going to use
recently, while working on a db2 -> oracle migration project, we came across this
Recently i am making an app on facebook. So i have use facebook api.
Recently downloaded some code for a minor open-source project related to a small webgame
Recently I've been doing quite the project mostly working with the DateTime class. Now,..
Recently I've read this performance guide Let's make the web faster and was puzzled
Recently we started working with Database project in Visual Studio 2010. I have added
Recently I worked in a project in where I need to display japanese text
Recently I faced a issue when using len() in a query to find out

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.