开发者

Exception "Element is already the child of another element." when navigating to the startup view

I'm using Region Navigation integrated with the Silverlight Frame Navigation as follows: I have my frame, to which I attached a region, and set the ContentLoader to the FrameContentLoader which I got from 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" />开发者_JAVA百科;
         <uriMapper:UriMapping Uri="/{pageName}" MappedUri="/MyProject.Views.{pageName}" />
      </uriMapper:UriMapper>
    </navigation:Frame.UriMapper>
</navigation:Frame>

I get the following exception: "Element is already the child of another element.", here's the stack trace:

   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)

this happens whenever I try to navigate to the Home view, whereas all the other navigation request complete successfully! To make sure that the problem isn't with the view itself, I tried replacing Home with About which is an existing view (making it the startup view), but the problem still exists! Now, I can navigate to Home but not About.

what could cause such a problem?

PS: the problem persists even after I removed the assignement of the Source property for the Frame, and the default UriMapper (the first one). With this, I have the error with the first view I visit, the others work fine.


I finally stumbled upon the "real cause" of this problem!

I found the following lines in my 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;
}

I'm not really sure as to what really happened here that caused the issue (maybe someone can enlighten me on that), but removing this solved the problem.

I hope this could help somebody (maybe a "future me") someday :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜