MVVM Light: Adding EventToCommand in XAML without Blend, easier way or snippet?

Suppose you use .NetFramework4: First add namespace: xmlns:cmd=”clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Platform” Syntax for the Loaded event. <i:Interaction.Triggers> <i:EventTrigger EventName=”Loaded”> <cmd:EventToCommand Command=”{Binding Mode=OneWay, Path=LoadedCommand}” PassEventArgsToCommand=”True” /> </i:EventTrigger> </i:Interaction.Triggers>

MVVM Light 5.0: How to use the Navigation service

Yes, MvvmLight introduced the NavigationService in their last version but they did’t offer any implementation regarding Wpf (you can use the Implemented NavigationService in WP, Metroapps, ..) but unfortunately not Wpf, you need to implement that by your self, here how i am currently doing it (credit) first create you navigation interface that Implements the … Read more

Implementing CollectionChanged

You have to add a PropertyChanged listener to each item (which must implement INotifyPropertyChanged) to get notification about editing objects in a observable list. public ObservableCollection<Item> Names { get; set; } public List<Item> ModifiedItems { get; set; } public ViewModel() { this.ModifiedItems = new List<Item>(); this.Names = new ObservableCollection<Item>(); this.Names.CollectionChanged += this.OnCollectionChanged; } void OnCollectionChanged(object … Read more

ViewModels in ViewModelLocator MVVM Light

First, lets look at what ViewModelLocator does and why we use it: ViewModelLocator is declared as an object on our App.xaml page and is an application singleton. We’re going to have one, and only one of them available to the application when it runs. ViewModelLocator is the source for all our ViewModels in MVVM Light. … Read more

how to use MVVMLight SimpleIoc? [closed]

SimpleIoc crib sheet: 1) You register all your interfaces and objects in the ViewModelLocator class ViewModelLocator { static ViewModelLocator() { ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); if (ViewModelBase.IsInDesignModeStatic) { SimpleIoc.Default.Register<IDataService, Design.DesignDataService>(); } else { SimpleIoc.Default.Register<IDataService, DataService>(); } SimpleIoc.Default.Register<MainViewModel>(); SimpleIoc.Default.Register<SecondViewModel>(); } public MainViewModel Main { get { return ServiceLocator.Current.GetInstance<MainViewModel>(); } } } 2) Every object is a singleton by … Read more

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

Intro In MVVM the usual practice is to have the Views find their ViewModels by resolving them from a dependency injection (DI) container. This happens automatically when the container is asked to provide (resolve) an instance of the View class. The container injects the ViewModel into the View by calling a constructor of the View … Read more

Issue with DependencyProperty binding

The primary problem is that you set your UserControl’s DataContext to itself in its constructor: DataContext = this; You should not do that, because it breaks any DataContext based Bindings, i.e. to a view model instance that is provided by property value inheritance of the DataContext property Instead you would change the binding in the … Read more