Search code examples
c#wpfmditabbed-interface

Add a xaml File in a main tabbed Window


I'm trying to create a application with tabbed interface. For now I have this kind of interface enter image description here

with this code

<Window x:Class="BMG.BackOffice.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        
    Title="MainWindow" Height="572" Width="776">

<TabControl>
    <TabItem>
        <TabItem.Header>
            <TextBlock>
                tab1
            </TextBlock>
        </TabItem.Header>
        <Label>Test for tab1</Label>
    </TabItem>

    <TabItem>
        <TabItem.Header>
            <TextBlock>
                tab2
            </TextBlock>
        </TabItem.Header>
    </TabItem>

    <TabItem>
        <TabItem.Header>
            <TextBlock>
                tab3
            </TextBlock>
        </TabItem.Header>            
    </TabItem>

    <TabItem>
        <TabItem.Header>
            <TextBlock>
              tab4
            </TextBlock>
        </TabItem.Header>
    </TabItem>
</TabControl>

I have already write other windows and I wonder if is it possible to "insert" these windows in the tabs (a window for a tab). So to replace <Label>Test for tab1</Label> by a window (.xaml file)

Thanks for response


Solution

  • Normally you would convert those window controls to UserControls and then embed those inside the TabItems.

    <TabItem>
            <TabItem.Header>
                <TextBlock>
                    tab1
                </TextBlock>
            </TabItem.Header>
            <MyUserControl />
    </TabItem>
    

    I don't know if you can have a window inside another window but reading this question Thomas Levesque says that one can't have another window inside a tabitem.