/ Published in: C#
This is a tab control whos tabs are bound and the content of each tab is also bound
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
----------------------------- [XAML] ----------------------------- <Window x:Class="TabBinding.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase" Title="MainWindow" Height="350" Width="525"> <Grid Name="MainGrid"> <TabControl Name="MyTabControl" ItemsSource="{Binding Countries}" > <TabControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding CountryName}" /> </DataTemplate> </TabControl.ItemTemplate> <TabControl.ContentTemplate> <DataTemplate> <ListView Name="ScenarioListBox" ItemsSource="{Binding People}" MinHeight="20" SelectionMode="Single" > <ListView.View> <GridView> <GridViewColumn Header="Name" Width="200"> <GridViewColumn.CellTemplate> <DataTemplate> <Label Content="{Binding Path=Name}" /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView> </DataTemplate> </TabControl.ContentTemplate> </TabControl> </Grid> </Window> ----------------------------- [.CS] ---------------------------------- using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace TabBinding { public class Person { public String Name { get; set; } } public class Country { public String CountryName { get; set; } public ObservableCollection<Person> People { get; set; } public Country() { } } /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> /// public partial class MainWindow : Window { public ObservableCollection<Country> Countries { get; set; } public MainWindow() { InitializeComponent(); MainGrid.DataContext = this; Countries.Add(England); Countries.Add(SAfrica); Countries.Add(Zimbabwe); } } }