In my application, I was generally using the ViewModel constructor without any parameter and locating my ViewModel from xaml like below.
<UserControl.Resources>
<ResourceDictionary>
<vm:TabViewModel x:Key ="vm" ></vm:TabViewModel>
</ResourceDictionary>
</UserControl.Resources>
By using this, I can reference my ViewModel properties easily at design time in the xaml.
<Grid x:Name="grid" DataContext="{Binding Source={StaticResource ResourceKey=vm}}">
However, since I would communicate between the two ViewModels, I started using Prism 6 (Event Aggregator).
public TabViewModel(IEventAggregator eventAggregator)
{
this.eventAggregator = eventAggregator;
tabPoco = new TabWindowPoco();
tabPoco.Tag = "tag";
tabPoco.Title = "Title";
tabPoco.ListDataList = new ObservableCollection<ListData>();
tabPoco.ListDataList.Add(new ListData() { Name = "First", Age = 10, Country = "Belgium" });
tabPoco.ListDataList.Add(new ListData() { Name = "Second", Age = 11, Country = "USA" });
tabPoco.ListDataList.Add(new ListData() { Name = "Third", Age = 12, Country = "France" });
}
I am using Bootstrapper to load the application.
Since I am using IEventAggregator, I am force to use prism:ViewModelLocator.AutoWireViewModel="True" to locate ViewModel. Otherwise, the application does not run. Now, I am not able to use ViewModel as resource and cannot attach it to DataContext.
I do not want Prism to automatically locate the respective ViewModel, I would like to have control over it. I would like to locate it in xaml and assign it to DataContext.
Does anyone know how do I achieve this?