Automatic open of a ModalDialog
Can anybody tell me why having this code sequence:
public MainWindow()
{
InitializeComponent();
if (!Utils.PingNetwork("http://google.com"))
{
LoadOfflineData(null, null);
}
}
private async void LoadOfflineData(object sender, RoutedEventArgs e)
{
MetroDialogOptions.ColorScheme = MetroDialogColorScheme.Accented;
var settings = new LoginDialogSettings
{
ColorScheme = MetroDialogOptions.ColorScheme
};
await this.ShowMessageAsync("Network issues", "No Internet access.", MessageDialogStyle.Affirmative, settings);
}
when I run the application I get a System.NullReference on the line with
await this.ShowMessageAsync("Network issues", "No Internet access.", MessageDialogStyle.Affirmative, settings);
? :unamused:
I reproduced your bug and stepped through the code execution. It hangs on (MetroWindow.cs):
public bool IsOverlayVisible()
{
return overlayBox.Visibility == Visibility.Visible && overlayBox.Opacity >= 0.7;
}
I found that overlayBox is not defined in code yet while initializing a window. overlayBox is defined when the window template is applied, which has not yet happened when you try to show your message. Try putting it in the Window.Loaded event instead.
Good one @Dotnetifier :) Thanks! :+1:
Will test it asap. ;)
@robertstefan Can I close this?
Yeah, it can be closed.