I'm using Silverlight 5 with Prism and MEF.
I am trying to replace my shell at runtime by reading a XAML file, create an UIElement from it and replace the old shell's content with the new UIElement. I am using XamlReader.Load()
for this.
This works, until I try to create Prism regions.
I can create a new Shell with just one prism region in it, but when I have two or more regions in the new shell, all I get is a blank screen in my browser, and no error messages.
Is there a way to debug this? And why is this happening?
Code:
Creating the UIElement and replacing the shell (in Shell.xaml.cs):
DependencyObject rootObject = XamlReader.Load(XAMLFileString) as DependencyObject;
UIElement customShell = rootObject as UIElement;
this.Content = customShell;
This works (one region):
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:prism="http://www.codeplex.com/prism">
<StackPanel>
<ContentControl prism:RegionManager.RegionName="Region1"/>
</StackPanel>
</UserControl>
This also works (two regular content controls):
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:prism="http://www.codeplex.com/prism">
<StackPanel>
<ContentControl Content="C1"/>
<ContentControl Content="C2"/>
</StackPanel>
</UserControl>
but this gives me a blank screen instead (two prism regions):
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:prism="http://www.codeplex.com/prism">
<StackPanel>
<ContentControl prism:RegionManager.RegionName="Region1"/>
<ContentControl prism:RegionManager.RegionName="Region2"/>
</StackPanel>
</UserControl>