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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:51:59+00:00 2026-05-15T22:51:59+00:00

I’m experimenting with MVVM and I can’t quite wrap my mind around it. I

  • 0

I’m experimenting with MVVM and I can’t quite wrap my mind around it.

I have a View (windows) that has several repeated controls.

Let’s say I have 4 textbox – button pairs. Their behavior should be the same, after pressing a button paired textbox says “Hello World!”

I have tried several options I could think of:

  1. One ViewModel, 4 string properties binded to textboxes, 1 command
    • When I bind each button to the same command I can’t tell which property needs to be set.
    • Passing enum to CommandParameter feels awkward.
  2. One ViewModel and UserControl that hosts a textbox and a button repeated 4 times.
    • Now I need to expose all the properties like Command, CommandParameter, Text etc.. Seems like a lot of work.
    • Still can’t say which property needs to be updated after click.
  3. Each UserControl has a ViewModel
    • This solves button clicking and setting property, but now I have no clue how to extract texts from nested ViewModels to the window ViewModel.

Is there any other way? I suspect DataTemplates could be of use, but I’m not sure how.

  • 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-15T22:52:00+00:00Added an answer on May 15, 2026 at 10:52 pm

    What you describe is such an abstract and contrived idea that it doesn’t warrant MVVM. You’re talking about TextBoxes and Buttons, which are all ‘View’, and not the MVVM way of thinking. You’d almost always start with a Model.

    There is no ‘Model’ per-se here though; your specification is literally to set the value of a TextBox on a Button click. The seemingly random list of ‘4’ items (picked out of nowhere) and a seemingly useless TextBox mean nothing.

    Putting that aside and assuming that you have a set of 4 business entities, each with a field on them that is user-editable, and an action that the user can trigger, you’d do this:

    • Create a ViewModel class to represent an item – eg MyItemModel
    • Create a ViewModel class to represent the set of items (likely it will just return a Collection of the first) – eg AllMyItemsListModel

    Then for the View:

    • Create an ItemsControl, with ItemsSource bound to an instance of the ‘collection’ of the second ViewModel class
    • For each ItemTemplate, have a template or UserControl for each item
    • Within the template or UserControl, bind the TextBox‘s Text property to the appropriate property of the first class
    • Bind the Button‘s Command property to a property on the first class returning an ICommand – using RelayCommand for example

    I don’t know what you mean about ‘extracting texts from nested ViewModels to the window ViewModel’ – what does that mean and why would you want to do it?

    Hope that helps.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I have an array which has BIG numbers and small numbers in it. I
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.