0

Recently I started using WPF creator to create my application for home use. Earlier I was only once using the Visual Studio with NET Framework windows apps to create application. I remember that there I was able to create a sub form which I designed on a different window and that I was able to drag it to the main window later and enable/disable it while running the application.

What I mean is that I would like to create a second window, like when you are clicking on the "File" pane in windows word - completly new window shows up, but it does not alter the state of the previous window(text you wrote) nor new Word window opens. How do I do it? I was looking for it on internet but I only found films where someone showed how to open a second(main) window on click.

Thank You!

justaguy
  • 1
  • 1
  • The "File" pane in word is showing a dialog. To get a dialog (modal window) create a window instance and call [`ShowDialog()`](https://learn.microsoft.com/en-us/dotnet/api/system.windows.window.showdialog?view=windowsdesktop-7.0) method instead of `Show()` – Sir Rufo Aug 16 '23 at 05:36
  • Does this answer your question? [WPF: Create a dialog / prompt](https://stackoverflow.com/questions/2796470/wpf-create-a-dialog-prompt) – Sir Rufo Aug 16 '23 at 05:38
  • Please feel free to let know if you have any question. – wenbingeng-MSFT Aug 21 '23 at 02:12

1 Answers1

0

You can achieve the effect of nested -like windows through ContentControl.

First of all, I put a ContentControl on the top left of Mainwindows. Its name is Changepage, and then a button is placed to trigger the embedded "sub -window".

enter image description here

Then, you need to create a page (here is page, not Windows), and set its background color to red.

enter image description here

enter image description here

Then the code in Mainwindows is as follows:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        string pageFileName = "ChildWindows.ChildPage1";
        Type t = Type.GetType(pageFileName);

        if (t != null)
        {
            ChangePage.Content = new Frame()
            {
                Content = Activator.CreateInstance(t)
            };
        }
    }

At this time, after starting the project, you will find that the previously created Page embedded in MainWindows

enter image description here

wenbingeng-MSFT
  • 1,546
  • 1
  • 1
  • 8