簡體   English   中英

將用戶控件添加到TabItem

[英]Adding a UserControl to a TabItem

最初,我的MainWindow(.xaml)具有一個堆棧面板和一個框架。 堆棧面板中有三個導航按鈕,並且框架具有三個頁面之一(基於用戶單擊的導航按鈕)。 但是,似乎因為我沒有在做Web應用程序,所以使用Frame(和Pages?)並不是解決問題的正確方法。 因此,我將堆棧面板和框架更改為單個tabcontrol(選項卡是之前的三個按鈕)。 我也將頁面更改為用戶控件。

但是,我很難找到一種無需使用Frame即可將Pages(現在為UserControls)放入Tabitem內容的方法。 我試圖在MainWindow xaml中完成所有這些操作。

我的MainWindow.xaml:

<Window x:Class="ConstructedLanguageOrganizerTool.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Height="454" Width="573">
    <Grid>
        <TabControl HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Name="tabControl1">
            <TabItem Header="Basics" Name="basicsTab">
                //What can I use here instead of Frame?
            </TabItem>

            <TabItem Header="Words" Name="wordsTab">
                <Grid>
                    <Frame Source="WordsPage.xaml"/>
                </Grid>
            </TabItem>

            ...
        </TabControl>
    </Grid>
</Window>

我會以錯誤的方式處理嗎? 我想我想使用某種數據綁定,也許嗎? 盡管我對數據綁定的研究越多,但對此我也就越感到困惑。

編輯:這是我的BasicsPage.xaml

<UserControl x:Class="ConstructedLanguageOrganizerTool.BasicsPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" x:Name="basicsPage" Height="349" Width="334">

    <Grid>
        // Grid Row and Column defs here

        //Number of textboxs and textblocks here.

    </Grid>
</UserControl>

您只需要創建一個UserControl實例並將其放在TabItem中

BasicsPage是您要放入TabItem的UserControl。 您要做的所有事情:

<TabItem Header="Basics" Name="basicsTab">
   <local:BasicsPage/>
</TabItem>

在類似於BasicsPage的根窗口中定義本地名稱空間:

<Window x:Class="ConstructedLanguageOrganizerTool.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:ConstructedLanguageOrganizerTool"> <-- HERE

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM