【发布时间】:2017-11-08 17:56:33
【问题描述】:
我创建了一个绑定到实现 IDataErrorInfo 的实体的 wpf 文本框。当文本框无效(它周围的红色框,因为它没有通过 IDataErrorInfo 验证)并且文本框的 IsEnabled 属性设置为 false 时,我可以多次单击文本框并且文本框内的文本被擦除(传递了 string.Empty到实体)。
这里发生了什么?这是预期的行为吗?
编辑:我删除了 isEnabled 并添加了 isreadonly 和 focusable。我意识到如果我没有点击文本框,如果验证失败,它就会被删除。
编辑:然后,我删除了焦点并再次尝试。这一次,在我单击代表验证的红线之前,没有任何内容被删除。
编辑:我的文本框位于 DataGridTemplateColumn 内的 DataTemplate 内。DataGridTemplateColumn 内的 CellTemplate。
调用栈如下:
MyCode.DLL!MyCode.Models.Entity.PropertyName.set(string value) 第 66 行 C# [本机到托管转换]
PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.SetValue(object item, object value) 未知 PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.UpdateValue(对象值)未知 PresentationFramework.dll!System.Windows.Data.BindingExpression.UpdateSource(对象值)未知 PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.UpdateValue() 未知 PresentationFramework.dll!System.Windows.Data.BindingExpression.UpdateOverride() 未知 PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.Update() 未知 PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.ProcessDirty() 未知 PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.Dirty() 未知 PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.SetValue(System.Windows.DependencyObject d,System.Windows.DependencyProperty dp,对象值)未知 WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty dp,对象值,System.Windows.PropertyMetadata 元数据,bool coerceWithDeferredReference,bool coerceWithCurrentValue,System.Windows.OperationType operationType,bool isInternal)未知 WindowsBase.dll!System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty dp,对象值)未知 PresentationFramework.dll!System.Windows.Data.BindingExpression.GetInitialValue(System.Windows.DependencyObject 目标,输出 System.Windows.Controls.ValidationError 错误)未知 PresentationFramework.dll!System.Windows.Data.BindingExpression.Activate(object item) 未知 PresentationFramework.dll!System.Windows.Data.BindingExpression.AttachToContext(System.Windows.Data.BindingExpression.AttachAttempt 尝试)未知 PresentationFramework.dll!System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(bool lastChance) 未知 PresentationFramework.dll!MS.Internal.Data.DataBindEngine.Task.Run(bool lastChance) 未知 PresentationFramework.dll!MS.Internal.Data.DataBindEngine.Run(object arg) 未知 PresentationFramework.dll!MS.Internal.Data.DataBindEngine.OnLayoutUpdated(object sender, System.EventArgs e) 未知 PresentationCore.dll!System.Windows.ContextLayoutManager.fireLayoutUpdateEvent() 未知 PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayout() 未知 PresentationCore.dll!System.Windows.UIElement.UpdateLayout() 未知 PresentationFramework.dll!System.Windows.Controls.DataGridCell.BeginEdit(System.Windows.RoutedEventArgs e) 未知 PresentationFramework.dll!System.Windows.Controls.DataGrid.OnExecutedBeginEdit(System.Windows.Input.ExecutedRoutedEventArgs e) 未知 PresentationFramework.dll!System.Windows.Controls.DataGrid.OnExecutedBeginEdit(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) 未知 PresentationCore.dll!System.Windows.Input.CommandBinding.OnExecuted(对象发送者,System.Windows.Input.ExecutedRoutedEventArgs e)未知 PresentationCore.dll!System.Windows.Input.CommandManager.ExecuteCommandBinding(object sender, System.Windows.Input.ExecutedRoutedEventArgs e, System.Windows.Input.CommandBinding commandBinding) 未知 PresentationCore.dll!System.Windows.Input.CommandManager.FindCommandBinding(object sender, System.Windows.RoutedEventArgs e, System.Windows.Input.ICommand command, bool execute) 未知 PresentationCore.dll!System.Windows.Input.CommandManager.OnExecuted(对象发送者,System.Windows.Input.ExecutedRoutedEventArgs e)未知 PresentationCore.dll!System.Windows.UIElement.OnExecutedThunk(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) 未知 PresentationCore.dll!System.Windows.Input.ExecutedRoutedEventArgs.InvokeEventHandler(System.Delegate genericHandler, object target) 未知 PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate 处理程序,对象目标)未知 PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(对象目标,System.Windows.RoutedEventArgs routedEventArgs)未知 PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(对象源,System.Windows.RoutedEventArgs args,bool reRaised)未知 PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject 发件人,System.Windows.RoutedEventArgs 参数)未知 PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args, bool trust) 未知 PresentationCore.dll!System.Windows.Input.RoutedCommand.ExecuteImpl(对象参数,System.Windows.IInputElement 目标,bool userInitiated)未知 PresentationCore.dll!System.Windows.Input.RoutedCommand.Execute(对象参数,System.Windows.IInputElement 目标)未知 PresentationFramework.dll!System.Windows.Controls.DataGrid.BeginEdit(System.Windows.RoutedEventArgs editingEventArgs) 未知 PresentationFramework.dll!System.Windows.Controls.DataGridCell.OnAnyMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e) 未知 PresentationFramework.dll!System.Windows.Controls.DataGridCell.OnAnyMouseLeftButtonDownThunk(object sender, System.Windows.Input.MouseButtonEventArgs e) 未知 PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) 未知 PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate 处理程序,对象目标)未知 PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(对象目标,System.Windows.RoutedEventArgs routedEventArgs)未知 PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(对象源,System.Windows.RoutedEventArgs args,bool reRaised)未知 PresentationCore.dll!System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject 发件人,System.Windows.RoutedEventArgs 参数,System.Windows.RoutedEvent newEvent)未知 PresentationCore.dll!System.Windows.UIElement.OnMouseDownThunk(object sender, System.Windows.Input.MouseButtonEventArgs e) 未知 PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) 未知 PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate 处理程序,对象目标)未知 PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(对象目标,System.Windows.RoutedEventArgs routedEventArgs)未知 PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(对象源,System.Windows.RoutedEventArgs args,bool reRaised)未知 PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject 发件人,System.Windows.RoutedEventArgs 参数)未知 PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args) 未知 PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args, bool trust) 未知 PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() 未知 PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs 输入) 未知 PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport) 未知 PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode 模式, int 时间戳, System.Windows.Input.RawMouseActions 动作, int x, int y, int wheel) 未知 PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd,MS.Internal.Interop.WindowMessage msg,System.IntPtr wParam,System.IntPtr lParam,ref bool 处理)未知 PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd,int msg,System.IntPtr wParam,System.IntPtr lParam,ref bool 处理)未知 WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd,int msg,System.IntPtr wParam,System.IntPtr lParam,ref bool 处理)未知 WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) 未知 WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate 回调,对象 args,int numArgs)未知 WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) 未知 WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority 优先级,System.TimeSpan 超时,System.Delegate 方法,对象参数,int numArgs)未知 WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) 未知 [AppDomain 转换]
【问题讨论】:
-
你能发个代码吗?
-
@Hille 今天晚些时候我会尝试发布一些代码。
标签: c# wpf textbox idataerrorinfo