2011-03-31 46 views
0

我使用地區導航集成了Silverlight的框架導航時,如下所示:我有我的框架,給我連着區域其中,並設置ContentLoaderFrameContentLoader這是我從拿到Karl Shiflett's example例外「元素已經是另一個元素的子元素。」導航到啓動視圖

<navigation:Frame 
    x:Name="ContentFrame" 
    Style="{StaticResource ContentFrameStyle}" 
    Source="/Home" 
    Navigated="ContentFrame_Navigated" 
    NavigationFailed="ContentFrame_NavigationFailed" 
    prism:RegionManager.RegionName="MainContentRegion"> 

    <navigation:Frame.ContentLoader> 
     <prism_Regions:FrameContentLoader RegionName="MainContentRegion"/> 
    </navigation:Frame.ContentLoader> 

    <navigation:Frame.UriMapper> 
     <uriMapper:UriMapper> 
     <uriMapper:UriMapping Uri="" MappedUri="/MyProject.Views.Home" /> 
     <uriMapper:UriMapping Uri="/{pageName}" MappedUri="/MyProject.Views.{pageName}" /> 
     </uriMapper:UriMapper> 
    </navigation:Frame.UriMapper> 
</navigation:Frame> 

我得到以下異常:「元素已經是另一個元素的孩子。」,這裏的堆棧跟蹤:

at MS.Internal.XcpImports.CheckHResult(UInt32 hr) 
    at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, DependencyObject doh) 
    at MS.Internal.XcpImports.SetValue(IManagedPeerBase doh, DependencyProperty property, Object obj) 
    at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value) 
    at System.Windows.DependencyObject.SetEffectiveValue(DependencyProperty property, EffectiveValueEntry& newEntry, Object newValue) 
    at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation) 
    at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet) 
    at System.Windows.Controls.ContentControl.set_Content(Object value) 
    at System.Windows.Navigation.NavigationService.CompleteNavigation(DependencyObject content) 
    at System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(IAsyncResult result) 

發生這種情況每當我試圖導航到首頁視圖,而其他所有的導航請求成功完成!爲了確保問題不在視圖本身,我試圖替換首頁關於這是一個現有的視圖(使其成爲啓動視圖),但問題仍然存在!現在,我可以導航到首頁但不是關於

什麼可能導致這樣的問題?

PS:即使我刪除了Source屬性爲Frame的assignement和默認UriMapper(第一個)的問題仍然存在。有了這個,我有我訪問的第一個視圖的錯誤,其他人工作正常。

回答

0

我終於偶然發現了這個問題的「真正原因」!

我發現在我的App.xaml

protected virtual void InitializeRootVisual() 
{ 
    BusyIndicator busyIndicator = new BusyIndicator(); 
    busyIndicator.Content = new Shell(); 
    busyIndicator.HorizontalContentAlignment = HorizontalAlignment.Stretch; 
    busyIndicator.VerticalContentAlignment = VerticalAlignment.Stretch; 
    this.RootVisual = busyIndicator; 
} 

以下行我真的不知道來這裏到底發生了什麼導致這個問題(也許有人可以賜教上),但除去該解決了這個問題。

我希望這可以幫助某人(也許是「未來我」)總有一天:)

相關問題