Tag: WPF/TabControl
MainWindow.xaml
<TabControl Name="tab" ItemsSource="{Binding Persons}"> <TabControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Id}"/> </DataTemplate> </TabControl.ItemTemplate> <TabControl.ContentTemplate> <DataTemplate> <TextBlock Text="{Binding Name}"/> </DataTemplate> </TabControl.ContentTemplate> </TabControl>
MainWindow.xaml.cs
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); this.Persons = new ObservableCollection<Person>(); this.Persons.Add(new Person() { Id = 1, Name = "中田英寿" }); this.Persons.Add(new Person() { Id = 2, Name = "中村俊輔" }); this.DataContext = this; } public ObservableCollection<Person> Persons { get; set; } }
Person.cs
public class Person { public int Id { get; set; } public string Name { get; set; } }
ContentTemplateSelectorを使って切り替えるのが簡単っぽい。
Templateごと定義しないとだめ?。結構めんどくさそう。