2012-10-18 2 views
0

저는 Silverlight 5와 Prism 및 MEF를 사용하고 있습니다.XamlReader.Load()를 사용하여 파일에서 프리즘 영역을 만드는 중 오류가 발생 했습니까?

런타임에 셸을 바꾸려면 XAML 파일을 읽고 UIElement를 만들고 이전 셸의 내용을 새 UIElement로 바꾸십시오. 나는 이것을 위해 XamlReader.Load()을 사용하고 있습니다.

프리즘 영역을 만들려고 할 때까지 작동합니다.

프리즘 영역이 하나만있는 새 셸을 만들 수 있지만 새 셸에 두 개 이상의 영역이 있으면 브라우저에서 빈 화면이 나타나고 오류 메시지가 표시되지 않습니다.

디버깅 할 수있는 방법이 있습니까? 왜 이런 일이 일어나는 것입니까?

UIElement에 작성 및 (Shell.xaml.cs에서) 쉘 교체 :

DependencyObject rootObject = XamlReader.Load(XAMLFileString) as DependencyObject; 
UIElement customShell = rootObject as UIElement; 
this.Content = customShell; 

이 작동 (한 지역) :이 또한 작동

<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> 

코드

(일반 콘텐트 컨트롤 2 개) :

<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> 
(210)

그러나 이것은 나에게 대신 빈 화면 (두 개의 프리즘 지역)를 제공합니다

<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> 

답변

0

나는 문제가 무엇인지 파악 : 실제로 예외가 있었다, 그러나 자동으로 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: 

원래 셸에 이미 존재하는 이름으로 영역을 만들려고했기 때문에 예외가 발생했습니다. 지역 이름을 변경 한 후에 모든 것이 효과가있었습니다.

아직도 두 영역이있는 흰색 화면이 있지만 하나의 영역이 아닌 (두 영역 모두 동일한 예외가 발생하여 한 영역도 작동하지 않아야 함) 이유는 알 수 없습니다.

_regionManager.Regions.Remove(regionname) 
:

가 동일한 영역 이름을 갖는다 서로 쉘을 대체하기 위해, 영역이 셀을 교체하기 전에 등록 될 수있다