简体   繁体   English

WPF C#-将窗口打包到页面中

[英]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. 我正在尝试将WPF窗口打包到Page类中,并将其显示为我的应用程序的一部分。 I really need build in application. 我真的需要在应用程序中构建。 Is it possible? 可能吗?

I created Page class MyPage.xaml with MyPage.xaml.cs. 我使用MyPage.xaml.cs创建了Page类MyPage.xaml。 In contructor of MyPage I have 在MyPage的构造函数中,我有

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(); 取消注释后/// _ 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. Window必须是元素树的根,并且您不能将Window添加为Page或任何其他视觉对象的子级。

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 . 您可以做的是将窗口的内容移动到UserControl并使用其中一个实例作为PageContent But you cannot use the window directly. 但是您不能直接使用窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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