简体   繁体   English

将窗口嵌入另一个

[英]Embed a Window into Another

I have two WPF applications which I wrote myself, App1 and App2. 我有两个自己编写的WPF应用程序App1和App2。 I wish to embed App2 into App1. 我希望将App2嵌入到App1中。

Currently, I am trying this: 目前,我正在尝试:

App2 app2 = new App2();
object content = app2.Content; //which is a grid
app2.Content = null;
mainGridOfApp1.Children.Add(content as UIElement);

It does appear, but there's a few problems: 它确实出现了,但是有一些问题:

  • It is not displayed correctly; 显示不正确; the button locations and other UIElements are all messed up. 按钮位置和其他UIElement都被弄乱了。
  • It covers the entire screen, although mainGridOfApp2 is fixed at a much smaller size. 它覆盖了整个屏幕,尽管mainGridOfApp2固定为小得多的尺寸。 The effect is like WindowState.Maximized . 效果就像WindowState.Maximized
  • I have applied a custom style (theme) in App2, but since App2's App.xaml is not read, the custom style is not applied. 我在App2中应用了自定义样式(主题),但是由于未读取App2的App.xaml,因此未应用自定义样式。 How do I apply it? 我该如何申请?

How do I embed App2 into App1 seamlessly? 如何将App2无缝嵌入到App1中? I do not want to start App2 as a separate process and setting App1 as the parent because that would mean it would always be on top of whatever UI component App1 have. 我不想将App2作为单独的进程启动,而不想将App1设置为父进程,因为这意味着它将始终位于App1拥有的任何UI组件之上。

EDIT: I have embedded App2 into App1. 编辑:我已经将App2嵌入到App1中。 I put the main grid of App2 into a UserControl , and loaded the UserControl from the Window. 我将App2的主网格放入UserControl ,并从Window加载了UserControl For App1's side, all I did was call the UserControl of App2 after referencing it. 对于App1而言,我所做的只是在引用它之后调用App2的UserControl

You can load App2 assembly into your App1 application and create an instance of the Window/UserControl that you want to display in the content. 您可以将App2程序集加载到App1应用程序中,并创建要在内容中显示的Window / UserControl的实例。

You'll need to make some changes to the App1 so that you can reference the types or maybe create a common assembly with the required interfaces you can tie them together with. 您需要对App1进行一些更改,以便您可以引用这些类型,或者创建具有所需接口的通用程序集,并将它们绑定在一起。

Think any solution (which doens't involve App2 having its own process and being hosted) will rely on changes to the source code. 认为任何解决方案(不涉及App2具有自己的进程并由其托管)都将依赖于对源代码的更改。

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

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