MahApps.Metro icon indicating copy to clipboard operation
MahApps.Metro copied to clipboard

Automatic open of a ModalDialog

Open robertstefan opened this issue 12 years ago • 4 comments

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:

robertstefan avatar Jul 20 '14 13:07 robertstefan

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.

Dotnetifier avatar Jul 21 '14 19:07 Dotnetifier

Good one @Dotnetifier :) Thanks! :+1:

Will test it asap. ;)

robertstefan avatar Jul 21 '14 19:07 robertstefan

@robertstefan Can I close this?

flagbug avatar Jul 23 '14 08:07 flagbug

Yeah, it can be closed.

robertstefan avatar Jul 23 '14 09:07 robertstefan