【问题标题】:Add a xaml File in a main tabbed Window在主选项卡式窗口中添加 xaml 文件
【发布时间】:2011-04-16 21:53:42
【问题描述】:

我正在尝试创建一个带有选项卡式界面的应用程序。现在我有这种界面

使用此代码

<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>

我已经编写了其他窗口,我想知道是否可以在选项卡中“插入”这些窗口(选项卡的窗口)。所以替换&lt;Label&gt;Test for tab1&lt;/Label&gt; 通过窗口(.xaml 文件)

感谢回复

【问题讨论】:

    标签: c# wpf mdi tabbed-interface


    【解决方案1】:

    通常您会将这些窗口控件转换为 UserControls,然后将它们嵌入 TabItems 中。

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

    我不知道您是否可以在另一个窗口内有一个窗口,但阅读this 问题 Thomas Levesque 说一个人不能在一个 tabitem 内有另一个窗口。

    【讨论】:

      【解决方案2】:

      您可以加载 Window 并获取其 Content 属性,因为 Window 本身不能是另一个控件的子控件。

      我应该注意到这是非常混乱,最好的解决方案可能是将Window的content变成一个UserControl,这样你就可以在Window 和 TabControl,我猜曾经可以称为复合 UI 重构。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-06
        • 1970-01-01
        • 2012-12-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多