1.6 KiB
1.6 KiB
PreviewLostKeyboardFocus is called repeatedly if its handler shows a Windows Forms message box
Scope
Edge
Version Introduced
4.5
Source Analyzer Status
Available
Change Description
Beginning in the .NET Framework 4.5, calling System.Windows.Forms.MessageBox.Show
from a UIElement.PreviewLostKeyboardFocus
handler will cause the handler to re-fire when the message box is closed, potentially resulting in an infinite loop of
message boxes.
- Quirked
- Build-time break
Recommended Action
There are two options to work around this issue -
- It may be avoided by calling
System.Windows.MessageBox.Show
instead ofSystem.Windows.Forms.MessageBox.Show
. - It may be avoided by showing the message box from a
LostKeyboardFocus
event handler (as opposed to aPreviewLostKeyboardFocus
event handler).
Affected APIs
M:System.Windows.ContentElement.add_PreviewLostKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventHandler)
M:System.Windows.IInputElement.add_PreviewLostKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventHandler)
M:System.Windows.UIElement.add_PreviewLostKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventHandler)
M:System.Windows.UIElement3D.add_PreviewLostKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventHandler)
Categories
Windows Forms Windows Presentation Foundation (WPF)