Пример #1
0
        public ChangePasswordWindow()
        {
            InitializeComponent();

            // Наблюдаем за изменением пароля во всех трёх формах сразу. При помощи Select выбираем только тот элемент который нас интересует.
            // Наблюдается ошибка многопоточности при использовании Throttle. Подробнее по ссылке.
            // https://stackoverflow.com/questions/8766812/cross-thread-exception-when-using-rx-throttle
            Observable.FromEventPattern <RoutedEventHandler, RoutedEventArgs>(h =>
            {
                CurrentPasswordBox.PasswordChanged   += h;
                NewPasswordBox.PasswordChanged       += h;
                NewRepeatPasswordBox.PasswordChanged += h;
            },
                                                                              h =>
            {
                CurrentPasswordBox.PasswordChanged   -= h;
                NewPasswordBox.PasswordChanged       -= h;
                NewRepeatPasswordBox.PasswordChanged -= h;
            })
            .Select(o => o)
            .Throttle(TimeSpan.FromMilliseconds(100))
            .ObserveOn(DispatcherScheduler.Current)
            .Subscribe(o =>
            {
                PasswordBox box = o.Sender as PasswordBox;
                if (box.Equals(CurrentPasswordBox))
                {
                    ViewModel.CurrentPassword = box.Password;
                }
                else if (box.Equals(NewPasswordBox))
                {
                    ViewModel.NewPassword = box.Password;
                }
                else if (box.Equals(NewRepeatPasswordBox))
                {
                    ViewModel.NewRepeatPassword = box.Password;
                }
            });

            this.WhenActivated(disposable =>
            {
                this.BindCommand(ViewModel, x => x.ValidateCommand, x => x.ValidateButton);
            });
        }
 /// <summary>
 /// Copies text between PasswordBox and PasswordBox2, then calls
 /// TextChanged_VerifyFields().
 /// </summary>
 /// <param name="sender">Either PasswordBox or PasswordBox2</param>
 /// <param name="e">action event args</param>
 private void PasswordChanged_VerifyFields(object sender, RoutedEventArgs e)
 {
     if (PasswordBox.Equals(sender))
     {
         PasswordBox2.Text = PasswordBox.Password;
     }
     else
     {
         PasswordBox.Password = PasswordBox2.Text;
     }
     TextChanged_VerifyFields(PasswordBox, null);
 }
        public void IfFocusPasswordHintUnable(object sender, RoutedEventArgs e)
        {
            PasswordBox passwordBox = (PasswordBox)(sender);

            if (passwordBox.Equals(txt_PW))
            {
                label_PW.Visibility = Visibility.Hidden;
                passwordBox.Focus();
            }
            else
            {
                label_PW_check.Visibility = Visibility.Hidden;
                passwordBox.Focus();
            }
        }
        public void PasswordHintEnable(object sender, RoutedEventArgs e)
        {
            PasswordBox passwordBox = (PasswordBox)(sender);

            if (passwordBox.Password.Length == 0)
            {
                if (passwordBox.Equals(txt_PW))
                {
                    label_PW.Visibility = Visibility.Visible;
                }
                else
                {
                    label_PW_check.Visibility = Visibility.Visible;
                }
            }
        }