I have a scenario. I am writing a WPF app using Prism 6.0, where I want to POP up a Child Window first that will have three buttons for three different UI design. Similar like this.
Based upon the Selection I will update the MainWindowViewModel
and will close the Child Window, and show the MainWindow
.
Until This part is good. But the problem is after this part, The three different buttons points to three different UI designs. Specially the ContentRegion1 and ContentRegion2. These two regions are different.
I have seen that if I put a command through a Button then this code runs successfully. But the same doesn't run if I put that in MainWindowViewModel
.
public MainWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
{
_regionManager = regionManager;
_eventAggregator = eventAggregator;
_regionManager.RequestNavigate("ContentRegion1", "firstUiDesign");
...
}
The MainWindowlooks like this ...
ContentRegion1 and ContentRegion2 are two designed in XAML in this way
<Border CornerRadius="15" Grid.Column="0">
<StackPanel>
<ContentControl prism:RegionManager.RegionName="ContentRegion1" />
</StackPanel>
</Border>
<Border CornerRadius="15" Grid.Column="1">
<StackPanel Grid.Column="1" Margin="2">
<ContentControl prism:RegionManager.RegionName="ContentRegion2" />
</StackPanel>
</Border>
However I am unable to figure out what I did wrong or what Extra thing I need to put into the code to make it work.
Even in the BootStrapper.cs also I have this code
BootStrapper Code:
protected override DependencyObject CreateShell()
{
//return base.CreateShell();
return Container.Resolve<MainWindow>();
}
protected override void InitializeShell()
{
Application.Current.MainWindow.Show();
}
protected override void ConfigureContainer()
{
base.ConfigureContainer();
Container.RegisterTypeForNavigation<TestUserControl>("firstUiDesign");
}
Can anybody help in this.
Don't use the ViewModelLocator
to create the MainWindowViewModel
. Create it yourself in the Bootstrapper
after the MainWindow
and the regions have been created:
protected override DependencyObject CreateShell()
{
return Container.Resolve<MainWindow>();
}
protected override void InitializeShell()
{
var mainWindowViewModel = Container.Resolve<MainWindowViewModel>();
Application.Current.MainWindow.DataContext = mainWindowViewModel;
Application.Current.MainWindow.Show();
}
protected override void ConfigureContainer()
{
base.ConfigureContainer();
Container.RegisterTypeForNavigation<TestUserControl>("firstUiDesign");
}
Remove this from MainWindow.xaml
:
prism:ViewModelLocator.AutoWireViewModel="True">