[英]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.