I am defining two regions in shell: MainRegion and ToggleRegion. The Toggle region contains a button on clicking on that button i want to change the region in Main Region.
Here is my xaml code for registering regions in shell.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" ></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
</Grid.RowDefinitions>
<ContentControl Grid.Row="0" Regions:RegionManager.RegionName="MainRegion"></ContentControl>
<ContentControl Grid.Row="1" Regions:RegionManager.RegionName="ToggleRegion"></ContentControl>
</Grid>
My Bootstrapper add MainModule where I am injecting view in Region
protected override IModuleCatalog CreateModuleCatalog()
{
var catalog = new ModuleCatalog();
catalog.AddModule(typeof (MainModule));
return catalog;
}
My MainModule class
public void Initialize()
{
regionManager.RegisterViewWithRegion("MainRegion", typeof(MainView));
regionManager.RegisterViewWithRegion("ToggleRegion", typeof(ToggleView));
}
On Running the application I can see MainView and ToggleView loaded in MainRegion and ToggleRegion. But when i click the button in toggle region to change the view in Main region. Main region view is not changing.
Code in my button click event
{
IRegion region = regionManager.Regions["MainRegion"];
var view = region.Views.SingleOrDefault();
region.Remove(view);
regionManager.RegisterViewWithRegion("MainRegion", typeof(ViewOnButtonClick));
region.Activate(view);
}
On debugging I can see region is removing MainView first then activating viewonbuttonclick but same is not reflecting in my xaml View.
What am I missing ?