Im trying to create a new WPF MVVM prism project, but when i try to add view to my region in shell there is a null reference exception for RegionManager property. Can anybody help me ? here is my code:
class Bootstrapper : UnityBootstrapper
{
public IRegionManager regionManager { get; set; }
public IRegionManager RegionManager
{
get
{
return regionManager;
}
set
{
regionManager = value;
}
}
protected override DependencyObject CreateShell()
{
return new Shell();
}
protected override void InitializeShell()
{
base.InitializeShell();
App.Current.MainWindow = (Window)this.Shell;
App.Current.MainWindow.Show();
this.RegionManager.RequestNavigate("MainRegion", new Uri("PartNumberView", UriKind.Relative));
}
protected override void ConfigureModuleCatalog()
{
base.ConfigureModuleCatalog();
}
}
shell xaml:
<Window x:Class="MechanicsPriceComparer.Shell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:prism="http://www.codeplex.com/prism"
xmlns:local="clr-namespace:MechanicsPriceComparer"
mc:Ignorable="d"
Title="MechanicPriceComparer" Height="450" Width="800">
<Grid>
<ItemsControl Name="NameOfMainRegion" prism:RegionManager.RegionName="MainRegion" ></ItemsControl>
</Grid>
</Window>
app.xaml:
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Bootstrapper bootstrapper = new Bootstrapper();
bootstrapper.Run();
}