Prism MVVM - How to pass an IEventAggregator to my ViewModel?

You have to resolve your dependency via unity. Have a look at the prism MVVM examples and the ui composition. There the view does not create the view model, but it is exactly the other way round.

The view model gets the view injected via constructor injection. The view model sets itself as view model for the view.

You have to resolve your dependency via unity. Have a look at the prism MVVM examples and the ui composition. There the view does not create the view model, but it is exactly the other way round.

The view model gets the view injected via constructor injection. The view model sets itself as view model for the view: public interface IView { IViewModel ViewModel{get;set;} } public interface IViewModel { } public View:UserControl, IView { public IViewModel ViewModel { get{return DataContext as IViewModel;} set{DataContext = value;} } } public ViewModel:IViewModel { public ViewModel(IView view, IEventAggregator eventAggregator) { view. ViewModel = this; //get the event... } } Using this approach you have to register the view model and the view to unity.

Afterwards you only have to resolve the view model, the view is injected by the container. To get the view to the right place on the user interface you have to register the view to a region using the RegionManager. When this is all set up, creating a new view model instance results in adding the view into the registered region so that it shows up on the user interface.

That's the correct way. – Maciek Feb 23 at 14:14 Thanks for the response. Where do you instantiate the view model?

– leeran88 Feb 23 at 16:03 @leeran88: We'd need to see more of your application to answer that. Essentially in this scenario you would instantiate the view first and then the viewmodel, and then marry the two. Your view would have to implement the IView interface as well in this scenario.

– Anderson Imes Feb 23 at 20:17.

Other than having the ViewModel hook itself into the data context of the view (which I don't like at all), there are two other options that I can think of in Silverlight. Utilize the ServiceLocator pattern to allow your static resources to create themselves via the container. MVVMLight has a fairly good pattern for this.

Use a framework like Caliburn. Micro, which plugs in a nice set of conventions that will wire up many things based on naming conventions, including bindings and viewmodels.

Maybe you've solved it already but emileinarsson.se/silverlight-4-mvvm-pris... this post explains how to use Unity in a MVVM environment.

Thanks for the response. I already solved it in a different pattern, but that's a great post. I'll subscribe your blog :) – leeran88 Mar 19 at 9:33.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions