tags:

views:

12

answers:

1

My scenario:

I have in my form a tabControl. I've extended the TabItem control to some other classes that I want to add the TabControl.

I need that each one of the ExtendedTabItem have a specific header and data template.

Something in the line of:

<DataTemplate DataType="ExtendedTabItem">
   <StackPanel Height="100" Width="90">
      <TextBlock Text="{Binding Path=Referencia}" FontSize="13" 
         HorizontalAlignment="Center" Margin="0,0,0,1" />
      <TextBlock Text="{Binding Path=Estado}" FontSize="9" 
         HorizontalAlignment="Center" Margin="0,0,0,1" />
   </StackPanel>
</DataTemplate>

And then I could simply


Class ExtendedTabItem : TabItem {
    // bla bla bla
}

Action()
{
   ExtendedTabItem A = new ExtendedTabItem();
   A.Header = SelectedItem.Referencia;
   tabControl1.Items.Add(A);
}

Is this doable? All my searches seem to point to the use of an DatTemplateSelector but it does not seem quite what I need.

A: 

I was able to work around by defining the Template at run time.

<DataTemplate x:Key="t1" DataType="l:CloseableTabItem">

A.ContentTemplate = this.FindResource("t1") as DataTemplate;

I' would still prefer a solution that would not need that.

upsfeup