[英]WPF window content as content of another window
我需要将我的窗口显示为另一个窗口的选项卡中,我使用以下方法
var childWindowEditor = new MainWindow(); //window to embed
object content = childWindowEditor.Content; //take out the content of the window to embed
childWindowEditor.Content = null;
EditorTab.Content = content; //just a tab in a tabbed group
它的工作正常,但问题是如果我想访问窗口类的功能呢?
我知道我应该将其创建为用户控件,但是有一种解决方案而不必将该窗口的内容创建为用户控件吗?
将内容投射到我从工作中获取内容的窗口吗?
您应该使用MVVM
模式。 您的ViewModel
将是childWindowEditor
的DataContext
。 所以你可以简单地做
EditorTab.DataContext = childWindowEditor.DataContext;
就是这样。 我真的建议您使用MVVM
。 它使您的生活更加轻松。
您可以使用页面和框架来显示页面。
像这样在选项卡上添加框架:
<TabItem> <Frame Name="Frame1"></Frame> </TabItem>
在框架内显示页面:
Frame1.Content = new MyPage1();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.