以编程方式添加数据透视项 [英] Programmatically add Pivot Items
本文介绍了以编程方式添加数据透视项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在数据透视控件中显示照片列表,所以我有这个xaml
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
推荐答案
您正在将i
(Image
)添加到Pivot
.而是将i
添加到p
,然后将p
(PivotItem
)添加到Pivot
.
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);
}
这篇关于以编程方式添加数据透视项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文