0

私は Windows 8 アプリを持っていますが、最近、「マスター ページ」を使用するようにリファクタリングしました。これは、ヘッダーやフッターなどのいくつかの一般的なコンポーネントを持つ 1 つの「レイアウト」があることを意味します。そのレイアウトには、フレームがあります。別のビューを表示するたびに、フレームにロードします。

これは、起動画面のタイプFrameが ではなくLayout、つまりLayoutAwarePage. これは、 App.xaml.cs で初期化する方法ですOnLaunched:

Layout rootFrame = Window.Current.Content as Layout;

if (rootFrame == null)
{
    rootFrame = new Layout();

ここで問題が発生します。設定のようないくつかのアイテムを含むチャーム フライアウトがあります。これらのフライアウトのレイアウトを含む素敵なビュー (Flayouts.xaml) を作成しました。そのビューのコード ビハインドは次のようになります。

public Flyouts()
{
    InitializeComponent();

    SettingsPane.GetForCurrentView().CommandsRequested += Flyouts_CommandsRequested;
}

void Flyouts_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
    // add some commands
}

そして、これをアプリで機能させる方法は次のとおりです。

Frame rootFrame = Window.Current.Content as Frame;

if (rootFrame == null)
{
    rootFrame = new CharmFlyoutLibrary.CharmFrame { CharmContent = new Flyouts() };

彼らがここで行っているのは、Frame「rootFrame」への割り当てです。しかし、マスターページに切り替えてから/型しかなくなっFrameたので、CharmFrame を割り当てることができません。この問題を解決するにはどうすればよいですか?LayoutLayoutAwarePage

誰?

4

1 に答える 1

1

フレーム内をナビゲートする場合、ナビゲート先のページはナビゲートの Content プロパティ内に配置されます。

したがって、最初にレイアウトに移動すると、コンテンツがページで満たされ、子ページに移動できます。以下に例を載せました

        Frame rootFrame = Window.Current.Content as Frame;
        // Do not repeat app initialization when the Window already has content,
        // just ensure that the window is active

        if (rootFrame == null) {
            // Create a Frame to act as the navigation context and navigate to the first page

            rootFrame = new Frame();

            //Associate the frame with a SuspensionManager key                                

            SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

            if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) {
                // Restore the saved session state only when appropriate
                try {
                    await SuspensionManager.RestoreAsync();
                } catch (SuspensionManagerException) {
                    //Something went wrong restoring state.
                    //Assume there is no state and continue
                }
            }

            // Place the frame in the current Window
            Window.Current.Content = rootFrame;
        }
        if (rootFrame.Content == null) {
            if (rootFrame.Navigate(typeof(Layout))) {
                var secondFrame = rootFrame.Content as Layout;
                if (!secondFrame.ContentFrame.Navigate(typeof(YourPage)) {

                throw new Exception("Failed to create initial page");
                }
            }
        }
于 2013-11-12T19:59:26.317 に答える