的最好辦法說你有這2類:
public class GridData
{
public string Name { get; set; }
public string Id { get; set; }
public string Location { get; set; }
}
public class TabItems
{
public string tabName { get; set; }
public List<GridData> ls { get; set; }
}
並設置TabControl.ItemsSource
到List<TabItems>
那麼你XAML的TabControl
可以是這樣的:
<TabControl>
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding tabName}"/>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding ls}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=Id, StringFormat='{}Id: {0}'}"/>
<TextBlock Text="{Binding Path=Name, StringFormat='{}Name: {0}'}"/>
<TextBlock Text="{Binding Path=Location, StringFormat='{}Location: {0}'}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
指定2 DataTemplates
。 TabControl.ItemTemplate
代表標題,TabControl.ContentTemplate
代表內容,在本例中爲ItemsControl
顯示ls
這個問題對我而言並不清楚。你想要將TabControl的'ItemsSource'綁定到'TabItems'的list/observablecollection? – har07