0

次のように、Silverlightフレームナビゲーションと統合されたリージョンナビゲーションを使用しています。リージョンアタッチしたフレームがあり、 KarlShiflettの例から取得したに設定します。ContentLoaderFrameContentLoader

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

これは、ホームビューに移動しようとするたびに発生しますが、他のすべてのナビゲーション要求は正常に完了します。ビュー自体に問題がないことを確認するために、Homeを既存のビューであるAboutに置き換えてみました(スタートアップビューにしました)が、問題はまだ存在します!これで、ホームに移動できますが、アバウトには移動できません。

何がそのような問題を引き起こす可能性がありますか?

SourcePS:のプロパティFrameデフォルト UriMapper(最初のプロパティ)の割り当てを削除した後も、問題は解決しません。これにより、最初にアクセスしたビューでエラーが発生し、他のビューは正常に機能します。

4

1 に答える 1

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

問題の原因となったここで実際に何が起こったのかはよくわかりませんが(誰かが私に教えてくれるかもしれません)、これを削除することで問題は解決しました。

私はこれがいつか誰か(多分「未来の私」)を助けることができることを願っています:)

于 2011-04-21T09:35:48.540 に答える