Questions tagged [viewmodel]

A view model or viewpoints framework is a framework which defines a coherent set of views to be used in the construction of an architecture. A view is a representation of a whole system from the perspective of a related set of concerns.

A view model or viewpoints framework in systems engineering, software engineering, and enterprise engineering is a framework which defines a coherent set of views to be used in the construction of a system architecture, software architecture, or enterprise architecture. A view is a representation of a whole system from the perspective of a related set of concerns.

Source: http://en.wikipedia.org/wiki/View_model

4827 questions
73
votes
3 answers

Jetpack Compose - Unresolved reference: observeAsState

I'm learning Jetpack Compose and I was trying to make a View Model for my @Composable. In documentation (https://developer.android.com/codelabs/jetpack-compose-state#3) for observing state changes in composable they use observeAsState but in my…
Valentin
  • 1,159
  • 1
  • 11
  • 22
70
votes
8 answers

'by viewModels()' Kotlin property delegate unresolved reference

I'm trying to implement viewmodel with kotlin. First I added the needed dependecies: implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.core:core-ktx:1.2.0' // ViewModel implementation…
Toni Joe
  • 7,715
  • 12
  • 50
  • 69
68
votes
10 answers

how to instantiate ViewModel In AndroidX?

I want to initialize ViewModel in Activity using androidx library I have tried what documentation says but it is not working. the ".of" is not resolved. import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import…
66
votes
1 answer

How to bind WPF button to a command in ViewModelBase?

I have a view AttributeView that contains all sorts of attributes. There's also a button that when pressed, it should set the default values to the attributes. I also have a ViewModelBase class that is a base class for all ViewModels I have. The…
kor_
  • 1,510
  • 1
  • 16
  • 36
64
votes
7 answers

ArgumentMatchers.any must not be null

I am trying to test ViewModel to make sure livedata gets updated correctly. However when using ArgumentMatchers.any() it fails with IllegalStateException saying: ArgumentMatchers.any(mViewModel.CountSubscriber::class.java) must not be…
Ana Koridze
  • 1,532
  • 2
  • 18
  • 28
55
votes
4 answers

Do i need to create automapper createmap both ways?

This might be a stupid question! (n00b to AutoMapper and time-short!) I want to use AutoMapper to map from EF4 entities to ViewModel classes. 1) If I call CreateMap() then do I also need to call CreateMap
BlueChippy
  • 5,935
  • 16
  • 81
  • 131
55
votes
2 answers

ValidateInput(false) vs AllowHtml

I have a form that is used to create a memo, to do that I am using a rich text editor to provide some styling, this creates html tags in order to apply style. When I post that text, the mvc throws an error to prevent potentially dangerous scripts,…
EricGS
  • 1,323
  • 2
  • 17
  • 42
54
votes
2 answers

ASP.Net MVC and state - how to keep state between requests

As a fairly experienced ASP.Net developer just recently starting using MVC, I find myself struggling a bit to change my mindset from a traditional "server control and event handler" way of doing things, into the more dynamic MVC way of things. I…
TMan
  • 1,305
  • 1
  • 13
  • 17
52
votes
2 answers

MVVM and collections of VMs

A common senario: A model with a collection of item models. E.g a House with a collection of People. How to structure this correctly for MVVM - particulary with regard to updating the Model and ViewModel collections with additions and deletes? Model…
Ricibob
  • 7,505
  • 5
  • 46
  • 65
47
votes
10 answers

How to get an Instance of ViewModel in activity in 2020/21?

I am new to the mvvm pattern. I created a ViewModel for the main activity. Now I want to get an instance of the ViewModel in the main activity. Most Tutorials and answers here on Stackoverflow suggest using ViewModelProviders.of(..., but this is…
Gerke
  • 926
  • 1
  • 10
  • 20
46
votes
7 answers

How to write a ViewModelBase in MVVM

I'm pretty new in WPF programming environment. I'm trying to write a program out using MVVM design pattern. I've did some studies and read up some articles related to it and many of a time I came across this thing called ViewModelBase I know what…
DriLLFreAK100
  • 1,575
  • 2
  • 16
  • 26
46
votes
6 answers

Should a user control have its own view model?

I have a window made up of several user controls and was wondering whether each user control have its own view model or should the window as a whole have only one view model?
AwkwardCoder
  • 24,893
  • 27
  • 82
  • 152
43
votes
5 answers

WPF: how to signal an event from ViewModel to View without code in codebehind?

I have quite simple (I hope :)) problem: In MVVM, View usually listens on changes of ViewModel's properties. However, I would sometimes like to listen on event, so that, for example, View could start animation, or close window, when VM signals.…
Tomáš Kafka
  • 4,405
  • 6
  • 39
  • 52
40
votes
12 answers

ViewModel in Kotlin: Unresolved Reference

I am trying to implement ViewModel in a 100% Kotlin app. Every piece of documentation I can find says I want to use this to get the ViewModel instance: ViewModelProviders.of(this).get(CustomViewModel::class.java) According to the docs, I should be…
40
votes
8 answers

ASP.NET MVC - Database entities or ViewModels?

I am currently working on an ASP.NET MVC project. Some developers on the team want to bind the auto-generated database entities directly to the Views. Other developers want to create tailor-made ViewModel's and bind those to the Views. Objectively,…
Alex York
  • 5,392
  • 3
  • 31
  • 27