以编程方式添加数据透视表项

时间:2010-12-14 12:50:47

标签: windows-phone-7 pivot

我想在数据透视表控件中显示照片列表,所以我有这个xaml

<Grid x:Name="LayoutRoot" Background="Transparent">
    <controls:Pivot x:Name="DiaporamaPivot">
    </controls:Pivot>
</Grid>

在我背后的代码中:

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

知道我为什么会遇到异常

1 个答案:

答案 0 :(得分:9)

您要将iImage)添加到Pivot。相反,将i添加到p,然后将pPivotItem)添加到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);
}