1

今日、Silverlight 5 (ria 1.0 sp2) にアップグレードされた Silverlight 4 (ria 1.0) アプリケーションがあります。

データグリッドからレコードを削除しようとすると、次のエラーが発生します。

System.Windows.Controls.DataGrid.OnRemovedElement (Int32 slotDeleted、オブジェクト itemDeleted、ブール値 isRow) で
System.Windows.Controls.DataGrid.RemoveElementAt (Int32 スロット、オブジェクト項目、ブール値 isRow) で
System.Windows.Controls.DataGrid.RemoveRowAt (Int32 rowIndex、オブジェクト項目) で
System.Windows.Controls.DataGridDataConnection.NotifyingDataSource_CollectionChanged (オブジェクトの送信者、NotifyCollectionChangedEventArgs e) で
System.Windows.Controls.DataGridDataConnection.<WireEvents>b__0 (DataGridDataConnection インスタンス、オブジェクト ソース、NotifyCollectionChangedEventArgs eventArgs) で
System.Windows.Controls.WeakEventListener`3.OnEvent (TSource ソース、TEventArgs eventArgs) で
System.Windows.Data.PagedCollectionView.OnCollectionChanged (NotifyCollectionChangedEventArgs args) で
System.Windows.Data.PagedCollectionView.ProcessRemoveEvent で (オブジェクトの removedItem、ブール値の isReplace)
System.Windows.Data.PagedCollectionView.ProcessCollectionChanged (NotifyCollectionChangedEventArgs args) で
System.Windows.Data.PagedCollectionView.<.ctor>b__0 (オブジェクトの送信者、NotifyCollectionChangedEventArgs args) で
System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged (NotifyCollectionChangedEventArgs e) で
System.Collections.ObjectModel.ObservableCollection`1.RemoveItem (Int32 インデックス) で
System.Collections.ObjectModel.Collection`1.Remove(T item) で
Allscripts.UECPortal.Client.Modules.PayerpathEnrollmentProfile.ViewModels.CompleteUserInformation.CompleteUserInformationViewModel.deleteUserCommandExcuted (オブジェクト パラメーター) で
Microsoft.Practices.Prism.Commands.DelegateCommand`1.<>c__DisplayClass6.<.ctor>b__2 (オブジェクト o) で
Microsoft.Practices.Prism.Commands.DelegateCommandBase.Execute (オブジェクト パラメーター) で
Microsoft.Practices.Prism.Commands.DelegateCommandBase.System.Windows.Input.ICommand.Execute (オブジェクト パラメーター) で
System.Windows.Controls.Primitives.ButtonBase.ExecuteCommand() で
System.Windows.Controls.Primitives.ButtonBase.OnClick() で
System.Windows.Controls.Primitives.ToggleButton.OnClick() で
System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp (MouseButtonEventArgs e) で
System.Windows.Controls.Control.OnMouseLeftButtonUp (コントロール ctrl、EventArgs e) で
MS.Internal.JoltHelper.FireEvent (IntPtr unmanagedObj、IntPtr unmanagedObjArgs、Int32 argsTypeIndex、Int32 actualArgsTypeIndex、文字列 eventName、UInt32 フラグ) で

DataGrid にバインドされている ObservableCollection に DomainContext.EntitySet をラップしているため、ObservableCollection からアイテムを削除しようとすると、このエラーが発生します。

また、EntitySet をデータグリッドに直接バインドし、EntitySet から項目を削除しようとしましたが、まだ同じエラーが発生しています。

4

2 に答える 2

2

[TemplatePart]一般に、コントロールのドキュメントに不要と記載されている場合を除き、カスタム テンプレート内のすべての に対して常にコントロールを定義する必要があります。これらの[TemplatePart]属性の意図は、コントロールが参照するコードの部分を文書化することです。テンプレートに重要な部分が欠けていることをコントロールが検出した場合、コントロールは例外をスローする必要があります。明らかに、Silverlight 5 Toolkit の DataGrid はこれを行いません。おそらく Microsoft は、垂直スクロールバーなしで使用することを意図していますか?

Silverlight 5DataGridクラスには_vScrollBar、コントロールのテンプレートから読み取った垂直スクロール バーを格納するフィールドがあります (テンプレートに存在する場合)。メソッドではOnRemovedElement、コードが最初に null_vScrollBar.Maximumかどうかを確認せずにプロパティを読み取ることがわかりました。_vScrollBarこれが、表示されている NullReferenceException がスローされている場所であると思われます。これは、Silverlight 5 DataGrid のバグだと思います。DataGrid は、テンプレートに垂直スクロールバーがないと文句を言うか、なくても対処する必要があります。

于 2012-01-26T21:01:03.023 に答える
1

問題を解決しました。

問題は次のとおりです: - データグリッドにはカスタム テンプレートがあります - テンプレートには VerticalScrollbar がありません [TemplatePartAttribute(Name = "VerticalScrollbar", Type = typeof(ScrollBar))]

行でデータグリッドを削除すると、高さの再計算が試行されます。このプロセスには、VerticalScrollbar が含まれます (非表示にする必要があります)。テンプレートにスクロールバーがないとすぐに、NullReferenceException が発生しました。VerticalScrollbar を datagrid テンプレートに追加したところ、問題は解決しました。

Silverlight 4 では、すべてが正常に機能していました。そこで質問があります。これは Silverlight 5 データグリッドの欠陥ですか? または、常にすべてのテンプレート パーツをカスタム テンプレートで定義する必要がありますか?

于 2012-01-26T17:07:11.520 に答える