I have this code in MainPage.xaml:
<controls:PivotItem Header="first">
<ListBox x:Name="MyListBox" Margin="0,0,-12,0" ItemsSource="{Binding ListBoxItem}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="132">
<TextBlock Text="{Binding text}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</controls:PivotItem>
And I need to create N PivotItem’s in runtime with such model. How can I do it?
Let your PivotItem delaration be a Static Resource.
Then in your Pivot declaration use it as a template for your items.
This way, each time you add something to a
MyCollectionInDataContext, aPivotItemis created according to your defined template.