If you want to fulfill your Pivot with a Collection of Items then you will need an ItemTemplate
. Simple example can look like this:
In XAML:
<Pivot Title="MY APPLICATION" x:Name="myPivot" CommonNavigationTransitionInfo.IsStaggerElement="True"
Margin="0,12,0,0" ItemsSource="{Binding}">
<Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Header}"/>
</DataTemplate>
</Pivot.HeaderTemplate>
<Pivot.ItemTemplate>
<DataTemplate>
<ListView ItemsSource="{Binding VacationItemViewModelItems}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,24">
<TextBlock Text="{Binding Name}" TextWrapping="WrapWholeWords"
Pivot.SlideInAnimationGroup="1" CommonNavigationTransitionInfo.IsStaggerElement="True"/>
<TextBlock Text="{Binding Value}" TextWrapping="WrapWholeWords"
Pivot.SlideInAnimationGroup="2" CommonNavigationTransitionInfo.IsStaggerElement="True"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DataTemplate>
</Pivot.ItemTemplate>
</Pivot>
In code behind you need to define properties for your items (I've extended class of your item):
public class VacationItemViewModel : BaseViewModel, INotifyPropertyChanged
{
public string Header { get; set; }
private string _name;
private string _value;
[DataMember]
public string Name
{
get { return _name; }
set { this.SetProperty(ref _name, value); }
}
[DataMember]
public string Value
{
get { return _value; }
set { this.SetProperty(ref _value, value); }
}
private ObservableCollection<VacationItemViewModel> vacationItemViewModelItems = new ObservableCollection<VacationItemViewModel>();
public ObservableCollection<VacationItemViewModel> VacationItemViewModelItems
{
get { return vacationItemViewModelItems; }
set { vacationItemViewModelItems = value; }
}
// ...
}
Then you can create items:
ObservableCollection<VacationItemViewModel> myPivotItems = new ObservableCollection<VacationItemViewModel>()
{
new VacationItemViewModel(){Name="Test1", Value="test1", Header="First Item"},
new VacationItemViewModel(){Name="Test1", Value="test1", Header="Second Item"}
};
foreach (var item in myPivotItems)
{
item.VacationItemViewModelItems = new ObservableCollection<VacationItemViewModel>()
{
new VacationItemViewModel(){Name="Test1", Value="test1"},
new VacationItemViewModel(){Name="Test1", Value="test1"}
};
}
this.myPivot.DataContext = myPivotItems;
The code above still needs many improvements and so on, but should fulfill Pivot with Items, basing on ItemTemplate.
Also avoid naming Controls/Objects with the same name as Type - e.g. <Pivot Name="Pivot" ...