我可以将数据输入到我的 TabControl 中,但标题周围有框架,我不能从一个选项卡到另一个选项卡。
我在这个 TabControl 上的 XAML 绑定语法做错了什么?
XAML:
<StackPanel>
<TabControl x:Name="TheTabControl">
<TabControl.ItemTemplate>
<DataTemplate>
<TabItem Header="{Binding LastName}">
<StackPanel Margin="10" Orientation="Horizontal">
<TextBlock Text="{Binding FirstName}"/>
<TextBlock Text=" "/>
<TextBlock Text="{Binding LastName}"/>
</StackPanel>
</TabItem>
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
<TabControl>
<TabItem Header="Tab1">
<TextBlock Text="This is a test of tab 1"/>
</TabItem>
<TabItem Header="Tab2">
<TextBlock Text="This is a test of tab 2"/>
</TabItem>
</TabControl>
</StackPanel>
后面的代码:
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
//create all
List<Customer> customers = new List<Customer>();
customers.Add(new Customer { FirstName = "Jim", LastName = "Smith", NumberOfContracts = 23 });
customers.Add(new Customer { FirstName = "Jane", LastName = "Smith", NumberOfContracts = 23 });
customers.Add(new Customer { FirstName = "John", LastName = "Tester", NumberOfContracts = 23 });
//show
TheListBox.ItemsSource = customers;
}
}
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int NumberOfContracts { get; set; }
}