Quantcast
Viewing all articles
Browse latest Browse all 18858

MVVM - Subscribe to control events in the ViewModel

In a ViewModel, I need to react to the KeyDown event in a listbox in a corresponding View. Normally I use technique as

_collectionView =
CollectionViewSource.GetDefaultView(someObservableCollection)
_collectionView.CurrentChanged += newEventHandler(collectionView_CurrentChanged);

from the VieMmodel to get hold of the 'CollectionView' in the view if I want to react to events like CurrentChanged a.o. Other times I will instantiate a CollectionView in the ViewModel, and bind directly to this CollectionView from the View (in XAML). This latter technique is used when an ObservableCollection is assigned to several Views.

But how is this all done when I need to get hold of a Control like a listBox, a button, etc. in order to bind to events? Is there an equivalent technique for this?


Best regards Jesper Odgaard Nielsen

Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>