user1590636
user1590636

Reputation: 1194

WPF window content as content of another window

i need to show my window as inside Tab of another window and i do it using the following

 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

its working fine, but the problem is what if i wanted to access the functions of the window class?

i know tha i should create it as user control, but is there a solution without having to create the content of that window as a user control?

would casting the content to the window that i got the content from work?

Upvotes: 0

Views: 597

Answers (2)

Florian
Florian

Reputation: 5994

You should use the MVVM pattern. Your ViewModel would be the DataContext of childWindowEditor. So you could simply do something like

EditorTab.DataContext = childWindowEditor.DataContext;

And that's it. I really recommend you to use MVVM. It makes your life much easier.

Upvotes: 1

MikkaRin
MikkaRin

Reputation: 3084

You may use Pages and frames to display pages.

Add the frame on tab like this:

<TabItem> <Frame Name="Frame1"></Frame> </TabItem>

Show page inside frame:

Frame1.Content = new MyPage1();

Upvotes: 0

Related Questions