好的,我正在阅读这篇文章,它展示了如何在当前 XAML 中将自定义添加TabItem
到 aTabControl
中,但是如果我想在 XAML中添加TabItems
到自定义中呢?TabControl
所以我创建了我的自定义TabControl
UserControl
。
<UserControl x:Class="myLibrary.MyTabControl">
<DockPanel LastChildFill="True">
<Grid DockPanel.Dock="Bottom"/>>
</DockPanel>
<TabControl x:Name=tc">
<TabControl.LayoutTransform>
<!-- Allows to zoom the control's content using the slider -->
<ScaleTransform CenterX="0"
CenterY="0"
ScaleX="{Binding ElementName=uiScaleSlider,Path=Value}"
ScaleY="{Binding ElementName=uiScaleSlider,Path=Value}"/>
</TabControl.LayoutTransform>
</TabControl>
</UserControl>
然后,我想将静态添加TabItems
到 中MyUserControl
UserControl
,如下所示
<UserControl x:Class="MyLibrary.Forms.MyTabForm"
xmlns:Utilities="clr-namespace:myLibrary;assembly=myLibrary">
<Utilities:MyTabControl DockPanel.Dock="Top">
<tc>
<tc.Items>
<TabItem Header="Tab 0"/>
<TabItem Header="Tab 1"/>
</tc.Items>
</tc>
</Utilities:MyTabControl>
</UserControl>
而不是使用默认的 WPF TabControl
:
<TabControl Name="tabControl1" Margin="0, 10, 0, 0" DockPanel.Dock="Top">
<TabItem Header="Tab 0 (0)" Name="tabItem0">
<Grid Name="tabItem0Grid" />
</TabItem>
<TabItem Header="Tab 1 (0)" Name="tabItem1">
<Grid Name="tabItem1Grid" />
</TabItem>