简体   繁体   中英

WPF C# - pack window into page

I'm trying to pack WPF Window into Page class and show it as a part of my application. I really need build in application. Is it possible?

I created Page class MyPage.xaml with MyPage.xaml.cs. In contructor of MyPage I have

public MyPage()
    {
        InitializeComponent();

        _prompt = new MyPrompt();
        _prompt.ReadLine += new ReadLineEventHandler(CommandHandler);
        //_prompt.Show();

        this.Content = _prompt;
    }

This of course doesn't work. After uncomment //_promt.Show(); line I have seperated window. Is any possibility to make this a part of page?

Is any possibility to make this a part of page?

No, it isn't. A Window must be the root of the element tree and you cannot add a Window as a child of a Page or any other visual I am afraid.

What you could do is to move the contents of your window into a UserControl and use an instance of this one as the Content of your Page . But you cannot use the window directly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM