开发者

Add a xaml File in a main tabbed Window

开发者 https://www.devze.com 2023-02-25 20:35 出处:网络
I\'m trying to create a application with tabbed interface. For now I have this kind of interface with this code

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

Add a xaml File in a main tabbed Window

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


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.


You could load the Window and get its Content property since a Window itself cannot be the child of another control.

I should note that this is very messy, the best solution is probably to turn the content of the Window into a UserControl, that way you can use it in the Window and the TabControl, once could call that composite UI refactoring i guess.

0

精彩评论

暂无评论...
验证码 换一张
取 消