Esempio n. 1
0
        internal ChangePasswordDialog(MetroWindow parentWindow, ChangePasswordDialogSettings settings)
            : base(parentWindow, settings)
        {
            InitializeComponent();
            CurrentPassword                = settings.InitialPassword;
            CurrentPasswordWatermark       = settings.CurrentPasswordWatermark;
            NewPasswordWatermark           = settings.NewPasswordWatermark;
            ValidatePasswordWatermark      = settings.ValidatePasswordWatermark;
            CurrentPasswordVisibility      = settings.CurrentPasswordVisibility;
            RecoveryEmailVisibility        = settings.RecoveryEmailVisibility;
            RecoveryEmailWatermark         = settings.RecoveryEmailWatermark;
            RecoveryEmailMessageVisibility = settings.RecoveryEmailMessageVisibility;
            RecoveryEmailMessage           = settings.RecoveryEmailMessage;
            ValidateEmailWatermark         = settings.ValidateEmailWatermark;
            ValidateEmailVisibility        = settings.RecoveryEmailVisibility;
            AuxiliaryButtonVisibility      = settings.AuxiliaryButtonVisibility;

            if (settings.EnablePasswordPreview)
            {
                object resource = Application.Current.FindResource("Win8MetroPasswordBox");
                if (resource != null && resource.GetType() == typeof(Style))
                {
                    PART_PasswordBox.Style  = (Style)resource;
                    PART_PasswordBox2.Style = (Style)resource;
                    PART_PasswordBox3.Style = (Style)resource;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a ChangePasswordDialog inside of the current window.
        /// </summary>
        /// <param name="window"></param>
        /// <param name="title"></param>
        /// <param name="message"></param>
        /// <param name="settings"></param>
        /// <returns></returns>
        public static Task <ChangePasswordDialogData> ShowChangePasswordAsync(this MetroWindow window, string title, string message, ChangePasswordDialogSettings settings = null)
        {
            window.Dispatcher.VerifyAccess();
            return(HandleOverlayOnShow(settings, window).ContinueWith(z =>
            {
                return (Task <ChangePasswordDialogData>)window.Dispatcher.Invoke(new Func <Task <ChangePasswordDialogData> >(() =>
                {
                    if (settings == null)
                    {
                        settings = new ChangePasswordDialogSettings();
                    }

                    //create the dialog control
                    ChangePasswordDialog dialog = new ChangePasswordDialog(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());
        }