Questions tagged [mvvm]

Model-View-ViewModel (MVVM) is an architectural design pattern for implementing user interfaces that separates the UI (the View) from its data (the Model) via its presentation logic (its ViewModel).

Model-View-ViewModel (MVVM) is an architectural design pattern for implementation of user interfaces. Its primary focus is on separation of concern between the View (UI) and the Model (Data) by using an intermediate layer called a ViewModel to enhance manageability, scalability, and testability.

It is used in all based frameworks including , , ,,, the ZK framework and frameworks including KnockoutJS. Popular .Net frameworks implementing the pattern include:

See Also:

29966 questions
181
votes
8 answers

This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread

I have a DataGrid which is populating data from ViewModel by asynchronous method.My DataGrid is :
Anindya
  • 2,616
  • 2
  • 21
  • 25
176
votes
17 answers

In MVVM should the ViewModel or Model implement INotifyPropertyChanged?

Most MVVM examples I have worked through have had the Model implement INotifyPropertyChanged, but in Josh Smith's CommandSink example the ViewModel implements INotifyPropertyChanged. I'm still cognitively putting together the MVVM concepts, so I…
Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047
174
votes
11 answers

Android ViewModel additional arguments

Is there a way to pass additional argument to my custom AndroidViewModel constructor except Application context. Example: public class MyViewModel extends AndroidViewModel { private final LiveData> myObjectList; private…
Mario Rudman
  • 1,899
  • 2
  • 14
  • 18
158
votes
3 answers

Good or bad practice for Dialogs in wpf with MVVM?

I lately had the problem of creating add and edit dialogs for my wpf app. All I want to do in my code was something like this. (I mostly use viewmodel first approach with mvvm) ViewModel which calls a dialog window: var result =…
blindmeis
  • 22,175
  • 7
  • 55
  • 74
157
votes
14 answers

Handling the window closing event with WPF / MVVM Light Toolkit

I'd like to handle the Closing event (when a user clicks the upper right 'X' button) of my window in order to eventually display a confirm message or/and cancel the closing. I know how to do this in the code-behind: subscribe to the Closing event of…
Olivier Payen
  • 15,198
  • 7
  • 41
  • 70
151
votes
9 answers

Good examples of MVVM Template

I am currently working with the Microsoft MVVM template and find the lack of detailed examples frustrating. The included ContactBook example shows very little Command handling and the only other example I've found is from an MSDN Magazine article…
jwarzech
  • 6,596
  • 11
  • 52
  • 72
148
votes
35 answers

Cannot create an instance of class ViewModel

I am trying to write a sample app using Android architecture components and but even after trying for days I could not get it to work. It gives me the above exception. Lifecycle owner:- public class MainActivity extends LifecycleActivity { …
Parag Kadam
  • 3,620
  • 5
  • 25
  • 51
147
votes
21 answers

Set focus on TextBox in WPF from view model

I have a TextBox and a Button in my view. Now I am checking a condition upon button click and if the condition turns out to be false, displaying the message to the user, and then I have to set the cursor to the TextBox control. if (companyref ==…
priyanka.sarkar
  • 25,766
  • 43
  • 127
  • 173
145
votes
6 answers

Is there a proper way of resetting a component's initial data in vuejs?

I have a component with a specific set of starting data: data: function (){ return { modalBodyDisplay: 'getUserInput', // possible values: 'getUserInput', 'confirmGeocodedValue' submitButtonText: 'Lookup', // possible values…
Chris Schmitz
  • 20,160
  • 30
  • 81
  • 137
141
votes
3 answers

What is Prism for WPF?

I've come across something called Prism a lot recently. Microsoft, who run the project, describe it as Guidelines for composite applications in WPF and Silverlight. Even after reading the more detailed descriptions out there, I have next to no…
Noldorin
  • 144,213
  • 56
  • 264
  • 302
136
votes
7 answers

SwiftUI - How to pass EnvironmentObject into View Model?

I'm looking to create an EnvironmentObject that can be accessed by the View Model (not just the view). The Environment object tracks the application session data, e.g. loggedIn, access token etc, this data will be passed into the view models (or…
Michael
  • 1,769
  • 2
  • 12
  • 21
134
votes
7 answers

Pushing read-only GUI properties back into ViewModel

I want to write a ViewModel that always knows the current state of some read-only dependency properties from the View. Specifically, my GUI contains a FlowDocumentPageViewer, which displays one page at a time from a FlowDocument.…
Joe White
  • 94,807
  • 60
  • 220
  • 330
131
votes
11 answers

MVVM in WPF - How to alert ViewModel of changes in Model... or should I?

I am going through some MVVM articles, primarily this and this. My specific question is: How do I communicate Model changes from the Model to the ViewModel? In Josh's article, I don't see that he does this. The ViewModel always asks the Model for…
Dave
  • 8,095
  • 14
  • 56
  • 99
129
votes
10 answers

How to handle dependency injection in a WPF/MVVM application

I am starting a new desktop application and I want to build it using MVVM and WPF. I am also intending to use TDD. The problem is that I don´t know how I should use an IoC container to inject my dependencies on my production code. Suppose I have the…
Fedaykin
  • 4,482
  • 3
  • 22
  • 32
119
votes
3 answers

What is a ViewModelLocator and what are its pros/cons compared to DataTemplates?

Can someone give me a quick summary of what a ViewModelLocator is, how it works, and what the pros/cons are for using it compared to DataTemplates? I have tried finding info on Google but there seems to be many different implementations of it and no…
Rachel
  • 130,264
  • 66
  • 304
  • 490