Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将UserControl添加到选项卡项_C#_Wpf_Xaml - Fatal编程技术网

C# 将UserControl添加到选项卡项

C# 将UserControl添加到选项卡项,c#,wpf,xaml,C#,Wpf,Xaml,最初我的主窗口(.xaml)有一个stackpanel和一个框架。stackpanel中有三个导航按钮,框架中有三个页面中的一个(根据用户单击的导航按钮)。然而,似乎因为我没有做一个web应用程序,所以使用框架(和页面?)不是正确的方法。因此,我将stackpanel和frame更改为单个tabcontrol(Tab是以前的三个按钮)。我还将页面更改为usercontrols 但是,我很难找到一种不使用框架就将页面(现在是UserControls)放入tabitem内容的方法。我试图在主窗口xa

最初我的主窗口(.xaml)有一个stackpanel和一个框架。stackpanel中有三个导航按钮,框架中有三个页面中的一个(根据用户单击的导航按钮)。然而,似乎因为我没有做一个web应用程序,所以使用框架(和页面?)不是正确的方法。因此,我将stackpanel和frame更改为单个tabcontrol(Tab是以前的三个按钮)。我还将页面更改为usercontrols

但是,我很难找到一种不使用框架就将页面(现在是UserControls)放入tabitem内容的方法。我试图在主窗口xaml中完成所有这些

my Main Window.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>

//我可以用什么来代替框架?
...
我走错方向了吗?我想我应该使用某种数据绑定,也许?尽管如此,我越是关注有关数据狂欢的事情,我也就越是对此感到困惑

编辑:这是我的BasicPage.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中即可

假设
basicpage
是要放在TabItem中的用户控件。您只需执行以下操作:

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

在根窗口中定义本地名称空间,其中BasicPage的定义类似于:

<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
您只需创建一个UserControl实例,并将其放入TabItem中即可

假设
basicpage
是要放在TabItem中的用户控件。您只需执行以下操作:

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

在根窗口中定义本地名称空间,其中BasicPage的定义类似于:

<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

将'xmlns:local=“clr namespace:basicpage'(您在回答中使用了单词,但它们只是不同的控件)添加到MainWindow.xaml,我被告知程序集中不包括名称空间'basicpage'。我做错什么了吗?我对问题进行了编辑,以显示BasicPage.xamlI已使用实际名称空间和BasicPage控件更新了答案。您需要在其中添加名称空间名称,而不是类名。我怀疑
ConstructedLanguageOrganizerTool
BasicPage
控件所在的命名空间。如果我想将datacontext传递给BasicPage怎么办?将“xmlns:local=“clr namespace:BasicPage”添加到main window.xaml中(您在回答中使用了单词,但它们只是不同的控件),我被告知名称空间“BasicPage”不包含在程序集中。我做错什么了吗?我对问题进行了编辑,以显示BasicPage.xamlI已使用实际名称空间和BasicPage控件更新了答案。您需要在其中添加名称空间名称,而不是类名。我怀疑
ConstructedLanguageOrganizerTool
BasicPage
控件所在的命名空间。如果我想将datacontext传递给BasicPage怎么办?