I have created a wpf textbox that is bound to an entity that implements IDataErrorInfo. When the textbox is invalidated (red box around it because it fails the IDataErrorInfo validation) and the textbox's IsEnabled property is set to false, I can click on the textbox multiple times and the text inside of the textbox is erased (string.Empty is passed to the entity).
What is going on here? Is this expected behavior?
Edit: I removed the isEnabled and added isreadonly and focusable. I realized that if I am not clicking in the text box, it erases if the validation fails.
Edit: Then, I removed the focusable and tried again. This time, nothing erased until I click right on the red line representing the validation.
Edit: My textbox lives inside of a DataTemplate inside of a DataGridTemplateColumn.CellTemplate inside of a DataGridTemplateColumn.
The callstack is below:
MyCode.DLL!MyCode.Models.Entity.PropertyName.set(string value) Line 66 C# [Native to Managed Transition]
PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.SetValue(object item, object value) Unknown PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.UpdateValue(object value) Unknown PresentationFramework.dll!System.Windows.Data.BindingExpression.UpdateSource(object value) Unknown PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.UpdateValue() Unknown PresentationFramework.dll!System.Windows.Data.BindingExpression.UpdateOverride() Unknown PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.Update() Unknown PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.ProcessDirty() Unknown PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.Dirty() Unknown PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.SetValue(System.Windows.DependencyObject d, System.Windows.DependencyProperty dp, object value) Unknown WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty dp, object value, System.Windows.PropertyMetadata metadata, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType, bool isInternal) Unknown WindowsBase.dll!System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty dp, object value) Unknown PresentationFramework.dll!System.Windows.Data.BindingExpression.GetInitialValue(System.Windows.DependencyObject target, out System.Windows.Controls.ValidationError error) Unknown PresentationFramework.dll!System.Windows.Data.BindingExpression.Activate(object item) Unknown PresentationFramework.dll!System.Windows.Data.BindingExpression.AttachToContext(System.Windows.Data.BindingExpression.AttachAttempt attempt) Unknown PresentationFramework.dll!System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(bool lastChance) Unknown PresentationFramework.dll!MS.Internal.Data.DataBindEngine.Task.Run(bool lastChance) Unknown PresentationFramework.dll!MS.Internal.Data.DataBindEngine.Run(object arg) Unknown PresentationFramework.dll!MS.Internal.Data.DataBindEngine.OnLayoutUpdated(object sender, System.EventArgs e) Unknown PresentationCore.dll!System.Windows.ContextLayoutManager.fireLayoutUpdateEvent() Unknown PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayout() Unknown PresentationCore.dll!System.Windows.UIElement.UpdateLayout() Unknown PresentationFramework.dll!System.Windows.Controls.DataGridCell.BeginEdit(System.Windows.RoutedEventArgs e) Unknown PresentationFramework.dll!System.Windows.Controls.DataGrid.OnExecutedBeginEdit(System.Windows.Input.ExecutedRoutedEventArgs e) Unknown PresentationFramework.dll!System.Windows.Controls.DataGrid.OnExecutedBeginEdit(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) Unknown PresentationCore.dll!System.Windows.Input.CommandBinding.OnExecuted(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) Unknown PresentationCore.dll!System.Windows.Input.CommandManager.ExecuteCommandBinding(object sender, System.Windows.Input.ExecutedRoutedEventArgs e, System.Windows.Input.CommandBinding commandBinding) Unknown PresentationCore.dll!System.Windows.Input.CommandManager.FindCommandBinding(object sender, System.Windows.RoutedEventArgs e, System.Windows.Input.ICommand command, bool execute) Unknown PresentationCore.dll!System.Windows.Input.CommandManager.OnExecuted(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) Unknown PresentationCore.dll!System.Windows.UIElement.OnExecutedThunk(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) Unknown PresentationCore.dll!System.Windows.Input.ExecutedRoutedEventArgs.InvokeEventHandler(System.Delegate genericHandler, object target) Unknown PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) Unknown PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) Unknown PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised) Unknown PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args) Unknown PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args, bool trusted) Unknown PresentationCore.dll!System.Windows.Input.RoutedCommand.ExecuteImpl(object parameter, System.Windows.IInputElement target, bool userInitiated) Unknown PresentationCore.dll!System.Windows.Input.RoutedCommand.Execute(object parameter, System.Windows.IInputElement target) Unknown PresentationFramework.dll!System.Windows.Controls.DataGrid.BeginEdit(System.Windows.RoutedEventArgs editingEventArgs) Unknown PresentationFramework.dll!System.Windows.Controls.DataGridCell.OnAnyMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e) Unknown PresentationFramework.dll!System.Windows.Controls.DataGridCell.OnAnyMouseLeftButtonDownThunk(object sender, System.Windows.Input.MouseButtonEventArgs e) Unknown PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) Unknown PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) Unknown PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) Unknown PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised) Unknown PresentationCore.dll!System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args, System.Windows.RoutedEvent newEvent) Unknown PresentationCore.dll!System.Windows.UIElement.OnMouseDownThunk(object sender, System.Windows.Input.MouseButtonEventArgs e) Unknown PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) Unknown PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) Unknown PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) Unknown PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised) Unknown PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args) Unknown PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args) Unknown PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args, bool trusted) Unknown PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() Unknown PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input) Unknown PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport) Unknown PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawMouseActions actions, int x, int y, int wheel) Unknown PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd, MS.Internal.Interop.WindowMessage msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) Unknown WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Unknown WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) Unknown WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) Unknown [AppDomain Transition]
I never figured out why, but I found that using CellTemplate
and CellEditingTemplate
fixed my issue.
To the people who downvoted my post and ran off, I'd recommend that you just ignore question in the future if you can't grasp on to the complexity.