In my WPF program I use the MahAps.Metro library and when I start the program I want to display a dialog box where I can enter my login / password.
But it throws a System.InvalidOperationException error. I do not understand what's the matter. Maybe because the method that displays the window in the constructor I call?
public MainWindow() // Конструктор { InitializeComponent(); LogIn(); } private async void LogIn() { LoginDialogData result = await this.ShowLoginAsync("Authentication", "Enter your credentials", new LoginDialogSettings { ColorScheme = this.MetroDialogOptions.ColorScheme, InitialUsername = "MahApps" }); } I have code that handles button presses. When clicked, a dialog box appears where you can enter a login / password. Inside the click handler, everything works, but if this code is copied to the method above, then again there will be the same error ...
private async void buttonLogOut_Click(object sender, RoutedEventArgs e) { var title = "Enter your credentials"; var settings = new LoginDialogSettings { ColorScheme = MetroDialogOptions.ColorScheme }; while (true) { var result = await this.ShowLoginAsync("Authentication", title, settings); if (result.Username == "dima" && result.Password == "123456") break; title = "Wrong data, try again"; } } 
OverlayBox can not be founded in this MetroWindow's template. Are you calling this before the window has loaded?OverlayBox can not be founded in this MetroWindow's template. Are you calling this before the window has loaded?- Dima KozyrLogIn();, andLoaded += (o, args) => LogIn();- VladD