I use Prism and Unity to rewrite a WPF application using the MVVM pattern. Most views are connected to the virtual machine through the DataContext property, for example:
<UserControl.DataContext> <VM:RibbonViewModel/> </UserControl.DataContext>
The problem is that this method will not work if there is a parameter in the ViewModel constructor.
public RibbonViewModel(IEventAggregator eventAggregator) { this.eventAggregator = eventAggregator; }
I get an error message:
The type "RibbonViewModel" cannot be used as an element of an object because it is not public or does not define an open constructor without parameters or a type converter.
How to connect a virtual machine to a view when there is a parameter?
source share