我有一個綁定到PagedCollectionView的DataGrid,並且底層集合可能不包含任何項目。當這種情況發生在DataGrid不會呈現在所有,任何列標題或任何東西,並在DataGrid,然後重新綁定到另一個PagedCollectionView不會包含一些項目它會導致系統錯誤是否有可能在Silverlight 3 Datagrid中顯示消息或默認行
System.ArgumentException:值 不在預期範圍內。
在 MS.Internal.XcpImports.MethodEx(IntPtr的 PTR,字符串名稱,CValue [] cvData)
在 MS.Internal.XcpImports.MethodEx(DependencyObject的 OBJ,字符串名稱)在 MS.Internal.XcpImports .UIElement_UpdateLayout(的UIElement 元件)...
或
消息:未處理的錯誤在Silverlight應用程序 代碼:4004
凱特血腥:ManagedRuntimeError
消息:System.ArgumentException:值不在預期範圍內。
在MS.Internal.XcpImports.CheckHResult(UInt32的小時)
在MS.Internal.XcpImports.Collection_InsertValue [T](1個PresentationFrameworkCollection收集,UInt32的索引,CValue值)
在MS.Internal.XcpImports.Collection_InsertDependencyObject [T ](PresentationFrameworkCollection 1收集,UInt32的索引,DependencyObject的值)
在System.Windows.PresentationFrameworkCollection 1.InsertDependencyObject(的Int32索引,DependencyObject的值)
在System.Windows.Controls.UIElementCollection.InsertInternal(的Int32索引,的UIElement值)
at System.Windows.PresentationFrameworkCollection 1.插入(Int32索引,T值)
在System.Windows.Controls.DataGrid.InsertDisplayedColumnHeader(的DataGridColumn的DataGridColumn)
在System.Windows.Controls.DataGrid.OnInsertedColumn_PreNotification(的DataGridColumn insertedColumn)
在System.Windows.Controls.DataGridColumnCollection.InsertItem(的Int32 columnIndex,的DataGridColumn的DataGridColumn )
在System.Collections.ObjectModel.Collection 1.Insert(的Int32索引,T項)
在System.Windows.Controls.DataGridColumnCollection.EnsureRowGrouping(布爾rowGrouping)
在System.Windows.Controls.DataGrid.EnsureRowGroupSpacerColumn( )
at System.Windows.Controls.DataGrid.RefreshRows(Boolean recy cleRows,布爾clearRows)
在System.Windows.Controls.DataGrid.RefreshRowsAndColumns(布爾clearRows)
在System.Windows.Controls.DataGrid.MeasureOverride(尺碼availableSize)
在System.Windows.FrameworkElement。的MeasureOverride(IntPtr的nativeTarget,單inWidth,單inHeight,單& outWidth,單& outHeight)
線:54
字符:13
代碼:0
我以爲是造成的,因爲在DataGrid是失蹤一個指針,它應該有(但說實話,我真的不知道,因爲我沒有看過它)。
系統異常顯然是一個問題,我希望它不會發生。但是如果集合中沒有項目是一個業務需求,那麼使用戶界面看起來很好,我認爲修復UI以在集合爲空時顯示一些很好的內容可能會給我一個系統異常的解決方法。
那麼是否有可能在Silverlight 3 DataGrid中顯示消息或默認行?
我見過Jonathan Shen's answer但是我想知道現在是否有更簡單/更簡單/內置的方式,因爲他的答案會在Silverlight 3之前發佈。我還有一個問題,必須在示例中創建,一個Person集合&對象。我的視圖沒有ViewModel的知識,所以爲了實現Jonathan的解決方案,我還必須在視圖中實現一個輔助人員 - 而不是世界的盡頭,但看起來有點冒險。
有沒有人有更好的解決方案來顯示一些好的時候綁定一個潛在的空集合到Silverlight DataGrid?
感謝馬克,這正是我最終做的 - 我甚至在我問了幾個小時後回過頭來回答我自己的問題,但有一些時間表,這是不可能的所以我從來沒有理解它。 麻煩的是,雖然這是一個很好的解決方案,但對於我的問題來說並不是一個好的答案,因爲沒有顯示空格的標題,如果添加了默認的「空行」,就會出現這個標題。不過,這是我使用的解決方案,所以對我來說這絕對夠用了。 – Scott 2009-12-17 02:41:25