Silverlight 使用XamlReader.Load()从文件创建棱柱区域时出错?

Silverlight 使用XamlReader.Load()从文件创建棱柱区域时出错?,silverlight,prism,mef,xamlreader,Silverlight,Prism,Mef,Xamlreader,我使用Silverlight 5和Prism和MEF 我试图在运行时通过读取一个XAML文件来替换shell,从中创建一个UIElement,并用新的UIElement替换旧shell的内容。我正在为此使用XamlReader.Load() 这是可行的,直到我尝试创建棱镜区域 我可以创建一个只有一个棱柱区域的新外壳,但是当我在新外壳中有两个或更多区域时,我得到的只是浏览器中的一个空白屏幕,并且没有错误消息 有办法调试这个吗?为什么会这样 代码: 创建UIElement并替换shell(在shel

我使用Silverlight 5和Prism和MEF

我试图在运行时通过读取一个XAML文件来替换shell,从中创建一个UIElement,并用新的UIElement替换旧shell的内容。我正在为此使用
XamlReader.Load()

这是可行的,直到我尝试创建棱镜区域

我可以创建一个只有一个棱柱区域的新外壳,但是当我在新外壳中有两个或更多区域时,我得到的只是浏览器中的一个空白屏幕,并且没有错误消息

有办法调试这个吗?为什么会这样

代码:

创建UIElement并替换shell(在shell.xaml.cs中):

这项工作(一个地区):


这同样有效(两个常规内容控件):


但这给了我一个空白屏幕(两个棱镜区域):


我发现了问题所在:实际上有一个异常,但它在App.xaml.cs中被静默处理:

Microsoft.Practices.Prism.Regions.Behaviors.RegionCreationException: An exception occurred while creating a region with name 'Region1'. The exception was: System.ArgumentException: Region with the given name is already registered: 
引发异常是因为我试图创建一个名称已存在于原始Shell中的区域。更改区域名称后,一切正常

我仍然不知道为什么我得到了一个有两个区域但没有一个区域的白色屏幕(两个区域都抛出了相同的异常,所以一个区域也不应该工作)

要用具有相同区域名称的另一个外壳替换外壳,可以在替换外壳之前注销这些区域:

_regionManager.Regions.Remove(regionname)
<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>
<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>
Microsoft.Practices.Prism.Regions.Behaviors.RegionCreationException: An exception occurred while creating a region with name 'Region1'. The exception was: System.ArgumentException: Region with the given name is already registered: 
_regionManager.Regions.Remove(regionname)