我正在尝试在两个透视项目中添加边框。
第一次将我的边框添加到枢轴项目中的网格时,一切正常。但是当我尝试在同一个透视项目中第二次添加边框时,会抛出异常“参数不正确” 这是我的代码:
private void pivot_item1Loaded()
{
WebClient webClient2011 = new WebClient();
string Url2011 = "http://hostname/Details/Images?year=2011" + "&time=" + System.DateTime.UtcNow;
webClient2011.OpenReadAsync(new Uri(Url2011));
webClient2011.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted2011);
}
private void pivot_item2Loaded()
{
WebClient webClient2012 = new WebClient();
string Url2012 = "http://hostname/Details/Images?year=2012" +"&time="+ System.DateTime.UtcNow;
webClient2012.OpenReadAsync(new Uri(Url2012));
webClient2012.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted2012);
}
public void webClient_OpenReadCompleted2011(object sender, OpenReadCompletedEventArgs e)
{
StringBuilder output = new StringBuilder();
try
{
using (XmlReader reader = XmlReader.Create(e.Result))
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "iconPath")
{
string iconPath = reader.ReadElementContentAsString();
iconImages2011.Add(iconPath);
}
if (reader.Name == "imagePath")
{
string imagePath = reader.ReadElementContentAsString();
fullScreenImages2011.Add(imagePath);
}
}
}
}
int numOfRows = (iconImages2011.Count) / 3 + 1;
for (int j = 0; j < numOfRows; j++)
{
//pivot_item1
ContentPanel2011.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(150) });
}
int rowCount = 0;
int columnCount = 0;
for (int i = 0; i < iconImages2011.Count; i++)
{
Border border2011 = new Border();
border2011.Background = new SolidColorBrush(Colors.Blue);
border2011.Height = 110;
border2011.Width = 110;
border2011.CornerRadius = new CornerRadius(10);
Canvas canvas2011 = new Canvas();
canvas2011.Height = 110;
canvas2011.Width = 110;
BitmapImage AppImage = new BitmapImage(new Uri(iconImages2011[i], UriKind.Absolute));
Image img = new Image();
img.Source = AppImage;
img.Width = 90;
img.Height = 90;
img.Stretch = Stretch.Fill;
img.Margin = new Thickness(10, 10, 10, 10);
canvas2011.Children.Add(img);
border2011.Child = canvas2011;
border2011.Name = i.ToString();
Grid.SetColumn(border2011, columnCount);
Grid.SetRow(border2011, rowCount);
ContentPanel2011.Children.Add(border2011);
pivot2011.Content = ContentPanel2011;
if (columnCount < 2)
{
columnCount++;
}
else if (columnCount == 2)
{
columnCount = 0;
rowCount++;
}
}
}
catch (Exception x)
{
MessageBox.Show(x.Message);
}
}
此代码首次运行但在此之后提供异常且ContentPanel2011 viz pivot_item1未填充border2011
答案 0 :(得分:0)
完成了。 在再次设置内容之前,只需将pivotots上的content属性设置为null。
我刚刚补充道:
pivot2011.Content = null;
pivot2012.Content = null;
<{1}}和pivot_item1Loaded()
中的
它工作正常。