Farshad
Farshad

Reputation: 325

Using Tabcontrol in MVVM pattern in WPF

I have multiple window files and i want to merge my Xaml files(window) into a Tab control in a MVVM Pattern. Each item Tab will represents a Xaml file. i need something like this:

 <TabControl >
        <TabItem>
            <local:FirstView></local:FirstView>
        </TabItem>

        <TabItem>
            <local:SecondView></local:SecondView>
        </TabItem>
 </TabControl>

but i get this Error:

"Window must be the root of the tree. Cannot add Window as a child of Visual."

I have seen many topics like this but they use user control or they use a single view with multiple View Model.

Is there any way to import window(xaml) into tab control?

And another important thing, i want to have a button like Cancel, Pushing Cancel means we have to go back one level(go to another tab Item). view model is not aware of view, so how can i navigate through them?

Upvotes: 1

Views: 145

Answers (1)

mm8
mm8

Reputation: 169390

Is there any way to import window(xaml) into tab control?

No, there isn't. A System.Windows.Window cannot be a child of another System.Windows.Window.

The contents of the tab items should be defined as UserControls.

You should just be able to move the contents of your windows to the user controls.

Upvotes: 5

Related Questions