Reputation: 15936
Look:
TabControl def:
<sdk:TabControl x:Name="tcWords">
<sdk:TabControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Letra}" />
<TextBlock Text="{Binding Palabra}" />
<TextBlock Text="{Binding Palabra}" />
</StackPanel>
</DataTemplate>
</sdk:TabControl.ItemTemplate>
</sdk:TabControl>
Code:
public class Termino
{
public string Letra { get; set; }
public string Palabra { get; set; }
public string Significado { get; set; }
}
List<Termino> arrPalabras = new List<Termino>();
arrPalabras.Add(new Termino { Letra = "A", Palabra = "Ave", Significado = "Cualquier cosa" });
arrPalabras.Add(new Termino { Letra = "A", Palabra = "Avion", Significado = "Cualquier cosa avion" });
//lstItems.ItemsSource = arrPalabras;
tcWords.ItemsSource = arrPalabras;
It throws an exception!!!
Unable to cast object of type 'Paradigma.Silverlight.DiccionarioDatos.Termino' to type System.Windows.Controls.TabItem'.
Upvotes: 0
Views: 925
Reputation: 137118
Your question is a bit unclear but you can't bind your class Termino
directly to the ItemsSource
of the TabControl
as it's not derived from TabItem
.
You can try changing your declaration to:
public class Termino : TabItem
{
....
}
I think this should work.
The documentation for TabControl.ItemsSource
doesn't really help has it points to the ItemsControl
page (which TabControl
inherits from) so the examples are for that rather than TabControl
.
Actually, thinking about it, you should be creating a list of TabItems
to set to the ItemsSource
of your TabControl
and binding your class to the TabItem
.
Upvotes: 1