Avalonia OnStartup or OnLoading override

Viewed 137

There is OnStartup or OnLoading in WPF, can be easily overriden and you can load some data when window is launching. But I can't find anything in Avalonia.

        private static MainWindow _mainWindow;
        public MainWindow()
        {           
            InitializeComponent();
            _mainWindow = this;

            try
            {
                StaticClass.LoadData();
            }
            catch (Exception exc)
            {
                var messageBoxStandardWindow = MessageBox.Avalonia.MessageBoxManager
  .GetMessageBoxStandardWindow("Error", exc.ToString());
                messageBoxStandardWindow.ShowDialog(_mainWindow);
                Environment.Exit(0);
            }

#if DEBUG
            this.AttachDevTools();
#endif
        }

This looks like it would work, but it doesn't. When exception is caught, it throws new exception: 'Cannot show window with non-visible parent.'. Basically MainWindow is not prepared at this point, and I can't load data here. This is why I need OnStartup alternative, but I can't find it.

MessageBox comes from MessageBox.Avalonia, because default Avalonia for some reason misses it.

0 Answers
Related