J'ai un TabControl dont ItemsSource est lié à une collection observable de vues (UserControls) qui ont chacun comme élément racine d'un TabItem. Cependant, lorsqu'il est affiché, l'en-tête texte est dans le contenu de chaque TabItem, comme si UserControl wrapper est à l'origine des conflits:Pourquoi les en-têtes d'onglet sont-ils affichés dans la zone de contenu des onglets d'un TabControl XAML?
alt text http://i31.tinypic.com/2z7pctz.png
TabControl est SmartFormView.xaml:
<UserControl x:Class="TestApp.Views.SmartFormView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel
Margin="10">
<TextBlock Text="{Binding Title}"
FontSize="18"/>
<TextBlock Text="{Binding Description}"
FontSize="12"/>
<TabControl
Margin="0 10 0 0"
ItemsSource="{Binding SmartFormAreaViews}"/>
</StackPanel>
</UserControl>
Que dois-je changer pour que les TabItems soient affichés sous forme de TabItems dans le TabControl?
Voici les vues TabItem appelé SmartFormAreaView.xaml:
<UserControl x:Class="TestApp.Views.SmartFormAreaView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TabItem Header="This is the header">
<StackPanel Margin="10">
<TextBlock Text="this is the content"/>
</StackPanel>
</TabItem>
</UserControl>
Et voici où je crée et charge de chaque vue dans le ObservableCollection:
var areas = from area in xmlDoc.Descendants("area")
select area;
foreach (var area in areas)
{
SmartFormArea smartFormArea = new SmartFormArea();
smartFormArea.IdCode = area.Attribute("idCode").Value;
smartFormArea.Title = area.Attribute("title").Value;
SmartFormAreaPresenter smartFormAreaPresenter = new SmartFormAreaPresenter(smartFormArea);
SmartFormAreaViews.Add(smartFormAreaPresenter.View as SmartFormAreaView);
}