开发者

Programmatically add Pivot Items

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  开发者_StackOverflow   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


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜