Navigating to a DataGrid using validation rules causes an exception.

Dec 15, 2008 at 1:03 AM
I have a WPF application with a page that hosts the DataGrid. I'm hitting an exception (details below) whenever I navigate to the page and the datagrid has an item that breaks a validation rule. The exception occurs during page creation (within InitializeComponent). 

Outside of not using validation, is there some behavior I can change which might prevent this? Alternatively, is there a code change I can make in the DataGrid that will solve this (or at least workaround it)?

Thanks,

-Craig

Message="'System.Windows.Data.BindingExpression' value cannot be assigned to property 'ItemsSource' of object 'Rigel.DataGrid'. 'DeferRefresh' is not allowed during an AddNew or EditItem transaction.  Error at object 'System.Windows.Data.Binding' in markup file 'Rigel;component/attributepage.xaml' Line 264 Position 25."
  Source="PresentationFramework"
  LineNumber=264
  LinePosition=25
  StackTrace:
      at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
      at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)
      at System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(Type type, Int16 typeId, Boolean throwOnFail)
      at System.Windows.Markup.BamlRecordReader.GetElementAndFlags(BamlElementStartRecord bamlElementStartRecord, Object& element, ReaderFlags& flags, Type& delayCreatedType, Int16& delayCreatedTypeId)
      at System.Windows.Markup.BamlRecordReader.BaseReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
      at System.Windows.Markup.BamlRecordReader.ReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
      at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
      at System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)
      at System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
      at System.Windows.Markup.TreeBuilder.Parse()
      at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
      at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
      at MS.Internal.AppModel.AppModelKnownContentFactory.BamlConverter(Stream stream, Uri baseUri, Boolean canUseTopLevelBrowser, Boolean sandboxExternalContent, Boolean allowAsync, Boolean isJournalNavigation, XamlReader& asyncObjectConverter)
      at MS.Internal.AppModel.MimeObjectFactory.GetObjectAndCloseStream(Stream s, ContentType contentType, Uri baseUri, Boolean canUseTopLevelBrowser, Boolean sandboxExternalContent, Boolean allowAsync, Boolean isJournalNavigation, XamlReader& asyncObjectConverter)
      at System.Windows.Navigation.NavigationService.GetObjectFromResponse(WebRequest request, WebResponse response, Uri destinationUri, Object navState)
      at System.Windows.Navigation.NavigationService.DoNavigate(Uri source, NavigationMode f, Object navState)
      at System.Windows.Navigation.NavigateQueueItem.Dispatch(Object obj)
      at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
      at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
      at System.Windows.Threading.DispatcherOperation.InvokeImpl()
      at System.Threading.ExecutionContext.runTryCode(Object userData)
      at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
      at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
      at System.Windows.Threading.DispatcherOperation.Invoke()
      at System.Windows.Threading.Dispatcher.ProcessQueue()
      at System.Windows.Threading.Dispatcher.WndProcHook(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, Boolean isSingleParameter)
      at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
      at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
      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.TranslateAndDispatchMessage(MSG& msg)
      at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
      at System.Windows.Application.RunInternal(Window window)
      at Rigel.App.Main() in C:\varigence\trunk\Rigel\Rigel\obj\Debug\App.g.cs:line 0
      at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
      at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
      at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
      at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.InvalidOperationException
      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, OperationType operationType)
            at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
            at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
            at System.Windows.Markup.BamlRecordReader.SetDependencyValueCore(DependencyObject dependencyObject, DependencyProperty dependencyProperty, Object value)
            at System.Windows.Markup.BamlRecordReader.SetDependencyComplexProperty(Object currentTarget, BamlAttributeInfoRecord attribInfo, Object o)
      InnerException:
Coordinator
Dec 15, 2008 at 4:14 PM
Edited Dec 17, 2008 at 3:09 AM

Hi Graig,

Thanks for reporting the issue.  Could you attach a simple reproduceable project? I’d like to investigate the issue further.

Thanks,
William

Dec 15, 2008 at 6:51 PM
I've posted an issue at http://www.codeplex.com/wpf/WorkItem/View.aspx?WorkItemId=8549, along with a reproduceable project.

Thanks,

-Craig