1

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?

4
  • 4
    Most probably, some of your views are windows. They should be usercontrols Commented Oct 3, 2017 at 15:20
  • As to the "cancel" problem I usually have the main view implement an "INavigation" interface that is then injected into the child view models. Commented Oct 3, 2017 at 15:24
  • @BradleyDotNET would you please explain it more? Commented Oct 3, 2017 at 19:05
  • @Farshad sounds like a different question; or you can bring it up in the WPF chat Commented Oct 3, 2017 at 20:19

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

So you mean Creating user Control is the only way?
Yes. A window cannot be a child of a TabItem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.