I'm new to WPF/MVVM and I'm working on a project where I've integrated Dragablz tab controls in such a way where I need the equivalent of new OEEView()
to instantiate a new Window into the content area of a new tab object.
However, in the ctor of the view I'm using (OEEView), it needs a viewModel passed to it. I tried creating a new OEESelectionViewModel within the tab instantiation code and pass it to the new OEEView() but its default ctor looks like public OEESelectionViewModel(IDialogService dialogService, IOEELogger oeeLogger, ISettingsManager settingsManager)
and I'm not sure how these I-objects are passed. From what I've gathered this is the responsibility of Prism and resolving dependencies using dependency injection. I've also tried creating a default(no-arg) constructor for OEEView and create a new OEESelectionViewModel within that, but I'm still stuck in terms of how to use Prism's DI.
public OEEView(OEESelectionViewModel viewModel)
{
InitializeComponent();
DataContext = viewModel;
_viewModel = viewModel;
}
public OEESelectionViewModel(IDialogService dialogService, IOEELogger oeeLogger, ISettingsManager settingsManager)
{
...
}
public TabView()
{
InitializeComponent();
var tab = new HeaderedItemViewModel
{
Header = new HeaderWithCloseViewModel
{
Header = "OEE Chart #1"
},
Content = new OEEView()
};
var viewModel = new TabViewModel(tab);
DataContext = viewModel;
_viewModel = viewModel;
this.Show();
}
I'd expect to be able to resolve a new instance and begin using it as if I used the new keyword but it isn't able to resolve itself automatically.
_container = new Container();
_container.Register<OEEView>(Reuse.Singleton);
OEEView client = _container.Resolve<OEEView>();
Additional information: Unable to resolve StationControl.ViewModels.OEESelectionViewModel as parameter "viewModel"