internal LoginDialog(IHandleDialogs parentWindow, LoginDialogSettings settings) : base(parentWindow, settings) { InitializeComponent(); Username = settings.InitialUsername; Password = settings.InitialPassword; UsernameWatermark = settings.UsernameWatermark; PasswordWatermark = settings.PasswordWatermark; NegativeButtonButtonVisibility = settings.NegativeButtonVisibility; ShouldHideUsername = settings.ShouldHideUsername; }
/// <summary> /// Creates a LoginDialog inside of the current window. /// </summary> /// <param name="window">The window that is the parent of the dialog.</param> /// <param name="title">The title of the LoginDialog.</param> /// <param name="message">The message contained within the LoginDialog.</param> /// <param name="settings">Optional settings that override the global metro dialog settings.</param> /// <returns>The text that was entered or null (Nothing in Visual Basic) if the user cancelled the operation.</returns> public static Task<LoginDialogData> ShowLoginAsync(this MetroWindow window, string title, string message, LoginDialogSettings settings = null) { window.Dispatcher.VerifyAccess(); return HandleOverlayOnShow(settings, window).ContinueWith(z => { return (Task<LoginDialogData>)window.Dispatcher.Invoke(new Func<Task<LoginDialogData>>(() => { if (settings == null) { settings = new LoginDialogSettings(); } //create the dialog control LoginDialog dialog = new LoginDialog(window, settings) { Title = title, Message = message }; SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog); dialog.SizeChangedHandler = sizeHandler; return dialog.WaitForLoadAsync().ContinueWith(x => { if (DialogOpened != null) { window.Dispatcher.BeginInvoke(new Action(() => DialogOpened(window, new DialogStateChangedEventArgs()))); } return dialog.WaitForButtonPressAsync().ContinueWith(y => { //once a button as been clicked, begin removing the dialog. dialog.OnClose(); if (DialogClosed != null) { window.Dispatcher.BeginInvoke(new Action(() => DialogClosed(window, new DialogStateChangedEventArgs()))); } Task closingTask = (Task)window.Dispatcher.Invoke(new Func<Task>(() => dialog._WaitForCloseAsync())); return closingTask.ContinueWith(a => { return ((Task)window.Dispatcher.Invoke(new Func<Task>(() => { window.SizeChanged -= sizeHandler; window.metroDialogContainer.Children.Remove(dialog); //remove the dialog from the container return HandleOverlayOnHide(settings, window); //window.overlayBox.Visibility = System.Windows.Visibility.Hidden; //deactive the overlay effect }))).ContinueWith(y3 => y).Unwrap(); }); }).Unwrap(); }).Unwrap().Unwrap(); })); }).Unwrap(); }
internal LoginDialog(MetroWindow parentWindow, LoginDialogSettings settings) : base(parentWindow, settings) { InitializeComponent(); Username = settings.InitialUsername; UsernameWatermark = settings.UsernameWatermark; PasswordWatermark = settings.PasswordWatermark; NegativeButtonButtonVisibility = settings.NegativeButtonVisibility; }
internal LoginDialog(MetroWindow parentWindow, LoginDialogSettings settings) : base(parentWindow, settings) { InitializeComponent(); Username = settings.InitialUsername; Password = settings.InitialPassword; UsernameWatermark = settings.UsernameWatermark; PasswordWatermark = settings.PasswordWatermark; NegativeButtonButtonVisibility = settings.NegativeButtonVisibility; ShouldHideUsername = settings.ShouldHideUsername; RememberCheckBoxVisibility = settings.RememberCheckBoxVisibility; RememberCheckBoxText = settings.RememberCheckBoxText; }
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 == loginResult.Username && result.Password == loginResult.Password) break; title = "Wrong data, try again"; } }
internal LoginDialog(MetroWindow parentWindow, LoginDialogSettings settings) : base(parentWindow, settings) { InitializeComponent(); Username = settings.InitialUsername; UsernameWatermark = settings.UsernameWatermark; PasswordWatermark = settings.PasswordWatermark; NegativeButtonButtonVisibility = settings.NegativeButtonVisibility; if (settings.EnablePasswordPreview) { object resource = Application.Current.FindResource("Win8MetroPasswordBox"); if (resource != null && resource.GetType() == typeof(Style)) { PART_TextBox2.Style = (Style)resource; } } }
/// <summary> /// Show Login Dialog /// </summary> /// <remarks>Miguel Santana 2015/03/11</remarks> /// <param name="control">Current control. In most cases use 'this'</param> /// <param name="message"></param> /// <param name="title"></param> /// <param name="settings">LoginDialogSettings sets properties for dialog fields and buttons</param> /// <example><see cref="LoginDialogData" /> result = await <see cref="DialogBox.ShowLoginDialog" />(...)</example> /// <returns>awaitable Task of type LoginDialogData</returns> /// <exception cref="WanderingTurtleException" /> public static Task<LoginDialogData> ShowLoginDialog(this FrameworkElement control, string message, string title = null, LoginDialogSettings settings = null) { return control.GetVisualParent<MetroWindow>().ShowLoginAsync(title, message, settings); }
private async void ToMonlist_Button_Click(object sender, RoutedEventArgs e) { var message = "Hierduch wird der gesamte, aktuell angezeigte Monat in MonList ersetzt. Alle Daten in MonList werden hierdurch überschrieben!"; if (this.ViewModel.MonlistImportLoginData != null) { var settings = new MetroDialogSettings() { AffirmativeButtonText = "Importieren", NegativeButtonText = "Abbrechen", }; MessageDialogResult result = await this.ShowMessageAsync("Monlist Daten-Import", message, MessageDialogStyle.AffirmativeAndNegative, settings); if (result == MessageDialogResult.Affirmative) { this.UploadToMonlist(this.ViewModel.MonlistImportLoginData.Password); } } else { var settings = new LoginDialogSettings { ShouldHideUsername = !string.IsNullOrWhiteSpace(this.ViewModel.Settings.MainSettings.MonlistEmployeeNumber), EnablePasswordPreview = true, AffirmativeButtonText = "Importieren", NegativeButtonText = "Abbrechen", NegativeButtonVisibility = Visibility.Visible }; LoginDialogData result = await this.ShowLoginAsync("Monlist Daten-Import", message + "\n\nPasswort", settings); if (result != null && !string.IsNullOrWhiteSpace(result.Password)) { // user pressed ok if (!settings.ShouldHideUsername) { this.ViewModel.Settings.MainSettings.MonlistEmployeeNumber = result.Username; } this.ViewModel.MonlistImportLoginData = result; this.UploadToMonlist(result.Password); } } }
public async Task<string> PopupString(string header = "Header", string message = "Message", bool concealed = false) { if (concealed == true) { LoginDialogSettings loginSettings = new LoginDialogSettings(); loginSettings.UsernameWatermark = "root"; loginSettings.InitialUsername = "******"; loginSettings.AffirmativeButtonText = "Ok"; var result = await this.ShowLoginAsync(header, message, loginSettings); if (result == null) //user pressed cancel return null; else return result.Password; } else { var result = await this.ShowInputAsync(header, message); if (result == null) //user pressed cancel return null; else return result; } }
private async void LoginAsyn() { LoginDialogSettings aSetting = new LoginDialogSettings { ColorScheme = MetroDialogOptions.ColorScheme, InitialUsername = "******", NegativeButtonVisibility = Visibility.Visible, EnablePasswordPreview = true }; LoginDialogData result = await this.ShowLoginAsync("登入验证", "输入用户名和密码", aSetting); if (result == null) { //User pressed cancel } else { string strurl = m_strLoginUrl; Encoding encoding = Encoding.UTF8; try { var controller = await this.ShowProgressAsync("请稍后...", "正在登入系统!"); controller.SetIndeterminate(); controller.SetCancelable(true); // Hashtable loginReturnData = await RealsunClientNet.Login(result.Username, result.Password); Hashtable loginReturnData = new Hashtable () ; loginReturnData.Add("error", 0); if (Convert.ToInt16(loginReturnData["error"]) == 0) { await controller.CloseAsync(); homepage.IsEnabled = true; homepage.IsSelected = true; clock.Controller.Stop(); Tiles.Visibility = Visibility.Visible; } else { await controller.CloseAsync(); homepage.IsEnabled = false; homepage.IsSelected = false; welcomepage.IsSelected = true; clock.Controller.Begin(); Tiles.Visibility = Visibility.Hidden; await this.ShowMessageAsync("登入失败", Convert.ToString(loginReturnData["message"])); } } catch (Exception) { } } }
/// <summary> /// Creates a LoginDialog inside of the current window. /// </summary> /// <param name="window">The window that is the parent of the dialog.</param> /// <param name="title">The title of the LoginDialog.</param> /// <param name="message">The message contained within the LoginDialog.</param> /// <param name="settings">Optional settings that override the global metro dialog settings.</param> /// <returns>The text that was entered or null (Nothing in Visual Basic) if the user cancelled the operation.</returns> public static Task <LoginDialogData> ShowLoginAsync(this MetroWindow window, string title, string message, LoginDialogSettings settings = null) { window.Dispatcher.VerifyAccess(); settings = settings ?? new LoginDialogSettings(); return(HandleOverlayOnShow(settings, window).ContinueWith(z => { return (Task <LoginDialogData>)window.Dispatcher.Invoke(new Func <Task <LoginDialogData> >(() => { //create the dialog control LoginDialog dialog = new LoginDialog(window, settings) { Title = title, Message = message }; SetDialogFontSizes(settings, dialog); SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog); dialog.SizeChangedHandler = sizeHandler; return dialog.WaitForLoadAsync().ContinueWith(x => { if (DialogOpened != null) { window.Dispatcher.BeginInvoke(new Action(() => DialogOpened(window, new DialogStateChangedEventArgs()))); } return dialog.WaitForButtonPressAsync().ContinueWith(y => { //once a button as been clicked, begin removing the dialog. dialog.OnClose(); if (DialogClosed != null) { window.Dispatcher.BeginInvoke(new Action(() => DialogClosed(window, new DialogStateChangedEventArgs()))); } Task closingTask = (Task)window.Dispatcher.Invoke(new Func <Task>(() => dialog.WaitForCloseAsync())); return closingTask.ContinueWith(a => { return ((Task)window.Dispatcher.Invoke(new Func <Task>(() => { window.SizeChanged -= sizeHandler; window.RemoveDialog(dialog); return HandleOverlayOnHide(settings, window); //window.overlayBox.Visibility = System.Windows.Visibility.Hidden; //deactive the overlay effect }))).ContinueWith(y3 => y).Unwrap(); }); }).Unwrap(); }).Unwrap().Unwrap(); })); }).Unwrap()); }
public Task <LoginDialogData> ShowLoginAsync(object context, string title, string message, LoginDialogSettings settings = null) { var metroWindow = GetMetroWindow(context); return(metroWindow.ShowLoginAsync(title, message, settings)); }
public async void ShowLoginDialog() { // note that setting allows much additional functionality LoginDialogSettings settings = new LoginDialogSettings() { NegativeButtonText = "Cancel", NegativeButtonVisibility= System.Windows.Visibility.Visible }; await _dialogCoordinator.ShowLoginAsync(this, "Please Login", "This login dialog was shown from Screen1ViewModel.", MessageDialogStyle.AffirmativeAndNegative, settings).ContinueWith(t => HandleLoginClose(t.Result)); }