wpf mvvm .. access view elements in viewmodel

Your ViewModels won't access the elements in the View directly. The concept is that the View will bind to the ViewModel, and not the other way around. So; your ViewModel will tell the View what to display through values set in properties. If your View needs to display something it will have a databinding to the property giving this.

The commands will be held by a ViewModel, and you can bind them too directly. If you need the command to update values for the View this can be done by holding a reference from the command to the necessary ViewModel. (The ViewModel holding the Command can e.g. inject itself to the command on creation). Then the command can tell the ViewModel to update something, and this will be reflected in the View through data bindings.

For general introduction to the MVVM pattern you can check out this question which was asked a few days ago: Learning MVVM for WPF.

Tags:

Wpf

Mvvm