Reputation: 6650
I want to display a list of photos in a Pivot Control, so I have this xaml
<Grid x:Name="LayoutRoot" Background="Transparent">
<controls:Pivot x:Name="DiaporamaPivot">
</controls:Pivot>
</Grid>
and in the code behind I do :
public Diaporama()
{
InitializeComponent();
PivotItem p = new PivotItem();
Image i = new Image();
i.Source = new BitmapImage(new Uri("/image.jpg", UriKind.Relative));
p.Margin = new Thickness(0, -10, 0, -2);
DiaporamaPivot.Items.Add(i);
}
Any idea why I get an exception
Upvotes: 2
Views: 7018
Reputation: 30830
You are adding i
(Image
) to Pivot
. Instead, add i
to p
and then, add p
(PivotItem
) to Pivot
.
public Diaporama()
{
InitializeComponent();
PivotItem p = new PivotItem();
Image i = new Image();
i.Source = new BitmapImage(new Uri("/image.jpg", UriKind.Relative));
p.Margin = new Thickness(0, -10, 0, -2);
p.Content = i;
DiaporamaPivot.Items.Add(p);
}
Upvotes: 9