gpt4 book ai didi

c# - WPF 项模板 - TabControl

转载 作者:太空宇宙 更新时间:2023-11-03 20:31:49 26 4
gpt4 key购买 nike

我正在编写一个应用程序,我在其中使用一个选项卡控件,该控件将从一个选项卡打开开始,但允许用户打开多个其他选项卡。

打开的每个选项卡都应该有一个 TreeView ,我在用户加载文件时使用数据绑定(bind)在其中填充。

我是 WPF 的新手,但我觉得好像有一种方法可以创建一个包含 TabItems 应包含的每个元素的模板。我如何使用模板来做到这一点?现在我的选项卡项目的 WPF 如下

<TabItem Header="Survey 1">
<TreeView Height="461" Name="treeView1" VerticalAlignment="Top"
Width="625" Margin="0,0,6,0" ItemTemplateSelector="{StaticResource TreeviewDataSelector}" />
</TabItem>

最佳答案

我想你想要这样的东西:

<Window x:Class="TestWpfApplication.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<DataTemplate x:Key="TabItemTemplate">
<TreeView Height="461" Name="treeView1" VerticalAlignment="Top"
Width="625" Margin="0,0,6,0" ItemTemplateSelector="{StaticResource TreeviewDataSelector}" />
</DataTemplate>

</Window.Resources>
<Grid>
<TabControl ItemsSource="{Binding ListThatPowersTheTabs}"
ItemTemplate="{StaticResource TabItemTemplate}">
</TabControl>
</Grid>

基本上,您可以将可重复使用的模板创建为静态资源,您可以通过它们的键名来引用它们。

关于c# - WPF 项模板 - TabControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7162879/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com