2013-02-22 21 views
5

私はDataGridにいくつかの行と列のデータを表示していますが、それぞれ独自のPropertyにバインドされています。 DataGridTabControlに属していませんが、そのウィンドウが閉じられて再度開くと、エラーメッセージが表示されます。 の場合は、DataGridのセルに1つ以上の確認の問題があります。例えばWPF DataGridが編集モードを終了していません

DataGridcelldoubleであり、ユーザが 『こんにちは』、もちろんその後WPF's自動赤い境界がcell周囲に表示される入射に結合性。今、ユーザがウィンドウを閉じてそれを再び開くと、エラーが発生します。

なぜ私はcellが「編集モード」を離れていないため、エラーがスローされていることがわかります。

このエラーを解決するにはどうすればよいですか?

その他の注意事項:

  • 私はthis questionを見てきましたが、それは(私ではない)TabControlDataGridに関連しています。
  • Celldoubleが必要な場合、またはdoubleしか受け付けないようにするには、ユーザの入力を制限しようとしましたが、問題がある場合、小数点( "。")の数を制限する良い方法はありません挿入することができます。私はユーザ入力をPreviewTextInputで制御しており、0〜9と "。"しか許可していません。

例外の詳細

System.InvalidOperationException was unhandled 
    Message='DeferRefresh' is not allowed during an AddNew or EditItem transaction. 
    Source=PresentationFramework 
    StackTrace: 
     at System.Windows.Data.CollectionView.DeferRefresh() 
     at System.Windows.Controls.ItemCollection.SetCollectionView(CollectionView view) 
     at System.Windows.Controls.ItemsControl.OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
     at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e) 
     at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e) 
     at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args) 
     at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) 
     at System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange) 
     at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange) 
     at System.Windows.Data.BindingExpression.Activate(Object item) 
     at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt) 
     at System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance) 
     at MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance) 
     at MS.Internal.Data.DataBindEngine.Run(Object arg) 
     at MS.Internal.Data.DataBindEngine.OnLayoutUpdated(Object sender, EventArgs e) 
     at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent() 
     at System.Windows.ContextLayoutManager.UpdateLayout() 
     at System.Windows.Interop.HwndSource.SetLayoutSize() 
     at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value) 
     at System.Windows.Window.SetRootVisualAndUpdateSTC() 
     at System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight) 
     at System.Windows.Window.CreateSourceWindow(Boolean duringShow) 
     at System.Windows.Window.ShowHelper(Object booleanBox) 
     at REACT.ViewModel.ReceiverListViewModel.ShowWindow(String name) in C:\Users\jcarroll42\Documents\Sandbox\REACT\SW\Source\ViewModel\ReceiverListViewModel.cs:line 238 
     at REACT.Commands.ShowWindowCommand.Execute(Object parameter) in C:\Users\jcarroll42\Documents\Sandbox\REACT\SW\Source\Commands.cs:line 137 
     at MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, Boolean userInitiated) 
     at System.Windows.Controls.Button.OnClick() 
     at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e) 
     at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) 
     at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) 
     at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) 
     at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) 
     at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) 
     at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) 
     at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) 
     at System.Windows.Input.InputManager.ProcessStagingArea() 
     at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) 
     at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) 
     at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
     at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
     at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
     at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) 
     at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 
     at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) 
     at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) 
     at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) 
     at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) 
     at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) 
     at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) 
     at System.Windows.Application.RunInternal(Window window) 
     at System.Windows.Application.Run() 
     at REACT.App.Main() in C:\Users\jcarroll42\Documents\Sandbox\REACT\SW\Source\obj\x86\Debug\App.g.cs:line 0 
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
    InnerException: 

を(この場合に役立ちます)必要であれば、私はもう情報を提供させていただきます。

+0

新しいウィンドウ/データグリッドインスタンスを毎回使用していますか? – Liju

+0

@Lijuはい、そうです。 –

+1

私はWindow Closingイベントの中でbuttonBlah.Focus()を呼び出すことによって同様の問題を解決しました。これは、LostFocusイベントを強制的にセルで発生させます。私が知っているかどうかは分かりません...もう一つの解決策は、ボタンが "保存"と "キャンセル"を使用して閉じられることだけです。 – Jack

答えて

5

これは、.NET Framework 4.5以降で修正されたバグです。残念ながら、以前のバージョンに悩まされている方々にとって、このエラーは依然として問題です。私が見つけた最良の解決策は、タイプstringDataGridpropertiesに単にバインドすることです。こうすることで、ユーザー入力に対する完全な制御が可能になります。フルコントロールでは、ユーザーはエラーを引き起こすことができず、DataGridはプログラムをクラッシュさせません。

+0

私はこの正確な問題を.NET 4.5.1に持っています。 – l33t

+0

@ l33tそれを修正しましたか?私も.NET 4.5を実行していて、まだこれを見ています。 – MarqueIV

+2

@Jordan、正確にこれが固定された/言及されたことを示す文書にリンクできますか?それは4.5か4.5.1、4.5.2などでしたか?私はそれが解決されたという検索で何も見つけられませんでした。 – MarqueIV

8

あなたは、あなたがそれを必要とするとき版を取り消すにデータグリッドを強制しようとすることができます:これは私のために働いた

myDatagrid.CommitEdit(); 
myDatagrid.CancelEdit(); 

行を並べ替えるとき、私は同様の問題がありました。

+1

をウィンドウを閉じますが、それは私が同様の問題を抱えていたねえ、私 – FrancescoDS

+0

@FrancescoDSのための問題を解決しないと、エラーがdataGrid.ItemsSource =データによってトリガーされていた、ライン、私は文字通り正しかった行の前に置きます。エラーの原因となって、それが私のために働いた - 私のためにそれをデータグリッド内のセルに誤ったダブルクリックによって引き起こされた(ダブルクリックしてプログラムを作っていたユーザーは、セルの内容を編集しようとしていたと考えているが、それはありませんでしたユーザーの意図) – ajivani

関連する問題