例外“元素已经是另一个元素的孩子。”导航到启动视图时

时间:2011-03-31 14:11:51

标签: silverlight-4.0 navigation prism-4

我正在使用与Silverlight框架导航集成的区域导航,如下所示:我有框架,我附加了区域,并设置了{{1我从Karl Shiflett's example得到的ContentLoader

FrameContentLoader

我得到以下异常:“元素已经是另一个元素的子元素。”,这是堆栈跟踪:

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

只要我尝试导航到主页视图,就会发生这种情况,而所有其他导航请求都已成功完成!为了确保问题不在视图本身中,我尝试将主页替换为关于这是一个现有视图(使其成为启动视图),但问题仍然存在!现在,我可以导航到主页,但不能关于

什么可能导致这样的问题?

PS:即使我删除了 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) 的{​​{1}}属性的分配,以及默认 Source(第一个),问题仍然存在。有了这个,我在访问的第一个视图中出现错误,其他人工作正常。

1 个答案:

答案 0 :(得分: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;
}

我不确定导致这个问题的真正发生的事情(也许有人可以启发我),但删除它解决了这个问题。

我希望有一天能帮助某人(也许是“未来我”):)