删除windowsphone中的数据透视项目
本文关键字:透视 项目 数据 windowsphone 删除 | 更新日期: 2023-09-27 18:00:37
我有大约30个图像,我想将它们作为项目保存在透视控件中。但如果我做了所有这些,我会遇到OutOfMemoryException。所以我在动态地添加枢轴。现在,如果我超过了某个限制,我想删除数据透视项目,但如果我在数据透视选择更改时删除,我会得到InvalidException。片段中的pivotshow是pivot控件。
void PivotShow_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
AddItems();
}
private void AddItems()
{
PivotItem toadd = PivotGen(images[i]);
i = (i + 1) % (images.Length);
PivotShow.Items.Add(toadd);
try
{
if (PivotShow.Items.Count > 3)
PivotShow.Items.RemoveAt(0);
}
catch (InvalidOperationException)
{
MessageBox.Show("Operation not allowed");
}
}
private PivotItem PivotGen(string urlimage)
{
PivotItem p = new PivotItem();
p.Margin = new Thickness(0, -90, 0, 0);
Image img = new Image();
BitmapImage bmp = new BitmapImage(new Uri(urlimage, UriKind.Relative));
img.Stretch = Stretch.Fill;
img.Source = bmp;
p.Content = img;
return p;
//PivotShow.Items.Add(p);
}
提前感谢
这很可能是因为您试图更改当前正在修改的集合。您可以按如下方式推迟代码:
EventHandler handler = null;
handler = (s, e) =>
{
element.LayoutUpdated -= handler;
AddItems();
};
element.LayoutUpdated += handler;
上面的代码将在下一次布局过程中调用AddItems
。试试看是否有帮助!