diff --git a/src/Shared/HandyControl_Shared/HandyControls/DynamicLanguage/LocalizationExtension.cs b/src/Shared/HandyControl_Shared/HandyControls/DynamicLanguage/LocalizationExtension.cs index 13fefaa84..5208944bd 100644 --- a/src/Shared/HandyControl_Shared/HandyControls/DynamicLanguage/LocalizationExtension.cs +++ b/src/Shared/HandyControl_Shared/HandyControls/DynamicLanguage/LocalizationExtension.cs @@ -122,12 +122,15 @@ public override object ProvideValue(IServiceProvider serviceProvider) // if provider is null again, mybe we are in usercontrol so we can use mainwindow provider if (ctlProvider == null) { - object localValue = Application.Current.MainWindow.ReadLocalValue(LocalizationManager.ProviderProperty); - if (localValue != DependencyProperty.UnsetValue) + if (Application.Current.MainWindow != null) { - if (localValue is ILocalizationProvider provider) + object localValue = Application.Current.MainWindow.ReadLocalValue(LocalizationManager.ProviderProperty); + if (localValue != DependencyProperty.UnsetValue) { - ctlProvider = provider; + if (localValue is ILocalizationProvider provider) + { + ctlProvider = provider; + } } } }