【发布时间】:2019-07-28 20:24:07
【问题描述】:
提前感谢您的支持!我正在尝试创建一个自定义选项卡项来充当动态创建 UI 元素的画布。这是一张图片,可以让我了解我想要在这个自定义控件中做什么:
我需要能够在父表单中为 TabControl 动态生成选项卡项 - 问题是我的代码似乎对 TabItem 没有任何作用 - 它始终是空白的,它不会抱怨我的代码。少了什么东西?感谢您的帮助!
我的 WPF 用户控件 tabitem 代码:
<UserControl x:Class="Configuration_Manager.SearchTab"
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"
xmlns:local="clr-namespace:Configuration_Manager"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<TabItem Header="Search Configuration Name">
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<GroupBox Header="Git Repo Credentials:">
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="Server Address:" />
<TextBox Grid.Column="1" Margin="2" />
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="Username:" />
<TextBox Grid.Column="1" Margin="2" />
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="Password:" />
<TextBox Grid.Column="1" Margin="2" />
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<CheckBox x:Name="CheckBoxStoreCredentials" Content="Store Credentials" Grid.Column="0" IsChecked="False" VerticalAlignment="Center"/>
<Button x:Name="ButtonDownloadConfiguration" Content="Download Configuration" Grid.Column="2" Margin="5" />
</Grid>
</StackPanel>
</GroupBox>
</Grid>
</StackPanel>
</TabItem>
</UserControl>
设计师:
【问题讨论】:
-
我不在 WPF 中使用自定义控件。我使用的是类型定位数据模板。在 WPF 中调整用户控件非常困难,但可以轻松复制和修改数据模板。
-
有趣 - 你能提供一个资源,也许是正确使用的视频?
-
我确实写了一篇关于 MVVM 的旧介绍,这是您应该与 WPF 一起使用的模式。它还处理数据模板。 social.msdn.microsoft.com/Forums/vstudio/en-US/…
-
您需要将 TabItem 放在 TabControl 中。