WrapPanel.Children.Add():System.ArgumentException:参数不正确

时间:2011-11-11 09:17:12

标签: c# silverlight windows-phone-7

我在Windows Phone(7.1)解决方案中有一个WrapPanel,我在其中添加和删除循环用户控件。大部分时间都有效,但有时我会收到以下错误:

"The parameter is incorrect. "
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.Collection_AddValue[T](PresentationFrameworkCollection`1 collection, CValue value)
at MS.Internal.XcpImports.Collection_AddDependencyObject[T](PresentationFrameworkCollection`1 collection, DependencyObject value)
at System.Windows.PresentationFrameworkCollection`1.AddDependencyObject(DependencyObject value)
at System.Windows.Controls.UIElementCollection.AddInternal(UIElement value)
at System.Windows.PresentationFrameworkCollection`1.Add(UIElement value)
at MyProject.Pages.DashboardPage.RefreshTiles()

我没有重现这个错误,它有时会弹出。我注意到,当我删除整个WrapPanel并创建一个新的错误时,永远不会弹出。因此,删除和添加项目似乎有些问题。 这是我的代码:

private void RefreshTiles()
{
    wrapPanelRooms.Children.Clear();

    foreach (Room room in Data.Inst.Rooms)
    {
        ControlRoomTile newTile = new ControlRoomTile{...};
        newTile.MouseLeftButtonUp +=
            (sender, e) =>
            this.NavigationService.Navigate(
                new Uri("/Pages/RoomDetailPage.xaml?id=" + ((ControlRoomTile)sender).Id, UriKind.Relative));
        try
        {
            this.wrapPanelRooms.Children.Add(newTile);
        }
        catch (Exception e)
        {
            Log.WriteLine(DateTime.Now.ToString("HH:mm:ss.ffff") + " UI: RefreshTiles ERROR1");
        }
    }
}

是否有人知道修复此问题?

0 个答案:

没有答案