UWP 内容对话框和内容框架

UWP Content Dialog and Content Frame

我的框架有点问题。

我写了一个静态方法,它绘制了一个内容对话框,里面有一个文本框,如果文本框不为空,它应该打开 page_2.

Currently I am using "ContentFrame.Navigate(typeof(Page_2), "operation");" ,

But my project have a pane Hamburguer menu on mainpage and it should be on all the pages. and if I use ContentFrame.Navigate it disappears.

这是我的静态内容对话框:

    public static async void D_NewProject(double Widthmax)
    {
        ContentDialog D_NewProject = new ContentDialog()
        {
            Title = "New Project",
            MaxWidth = Widthmax, // this.ActualWidth,
        };

        StackPanel D_panel = new StackPanel();


        TextBox TextBox_D1 = new TextBox()
        {
            PlaceholderText = "Name:",
            TextWrapping = TextWrapping.Wrap,
        };

        D_panel.Children.Add(TextBox_D1);

        D_NewProject.Content = D_panel;


        D_NewProject.PrimaryButtonText = "OK";
        D_NewProject.PrimaryButtonClick += delegate
        {
            if (TextBox_D1.Text != "")
            {
            /**/
                Frame ContentFrame = Window.Current.Content as Frame;
                ContentFrame.Navigate(typeof(Page_2), "operation");
            /**/
            }
        };
        await D_NewProject.ShowAsync();
    }

如果您需要更多类似窗格的代码,您可以提出要求。 感谢任何帮助。

如果您想要一个在所有页面中都处于活动状态的布局页面, 您需要在 App.xaml.cs 中创建一个方法,将当前页面加载到此布局中。 我可以向您推荐我自己使用的方法:

public static void LoadLayout(Type pageType)
{
    // just ensure that the window is active
    RootFrame = new _Layout();
    RootFrame.ContentFrame.Navigate(pageType, null);
    RootFrame.ContentFrame.Navigated += ContentFrame_Navigated;
    ContentFrame_Navigated(null, null);
    Window.Current.Content = RootFrame;
}

ContentFrame_Navigated 委托仅用于控制布局上的项目(例如:按钮,...)。