diff --git a/Gu.Wpf.NumericInput/Touch/TextBox.cs b/Gu.Wpf.NumericInput/Touch/TextBox.cs index 15652e7..30fe05b 100644 --- a/Gu.Wpf.NumericInput/Touch/TextBox.cs +++ b/Gu.Wpf.NumericInput/Touch/TextBox.cs @@ -29,11 +29,14 @@ static TextBox() typeof(System.Windows.Controls.TextBox), UIElement.LostFocusEvent, new RoutedEventHandler(OnLostFocus)); - var mainWindow = Application.Current?.MainWindow; - if (mainWindow != null) + Application.Current.Dispatcher.Invoke(() => { - mainWindow.Closed += OnClosed; - } + var mainWindow = Application.Current?.MainWindow; + if (mainWindow != null) + { + mainWindow.Closed += OnClosed; + } + }); } /// Helper for setting on .