using System.Windows; using System.Windows.Controls; using System.Windows.Input; using Muchinfo.MTPClient.Account.ViewModels; using Muchinfo.WPF.Controls.Windows; using System.Collections.Generic; namespace Muchinfo.MTPClient.Account.Views { /// /// TradeLoginView.xaml 的交互逻辑 /// public partial class TradePWDModifyView : Window { /// /// 是否非强制更新 /// /// if set to true [is unforce update]. public TradePWDModifyView(bool isUnforceUpdate) { InitializeComponent(); this.DataContext = new TradePWDModifyViewModel(isUnforceUpdate); setFocusList.Add(fundComBoxBox); fundComBoxBox.GotFocus += fundComBoxBox_GotFocus; //UserpasswoBox.Password = string.Empty; //FundsAccountTextBox.Focus(); this.KeyDown += TradePWDModifyView_KeyDown; } void TradePWDModifyView_KeyDown(object sender, KeyEventArgs e) { //避免按Alt+F4关闭窗口 if (e.KeyboardDevice.Modifiers == ModifierKeys.Alt && e.SystemKey == Key.F4) { e.Handled = true; } } void fundComBoxBox_GotFocus(object sender, RoutedEventArgs e) { var index = setFocusList.FindIndex((item) => sender.Equals(item)); if (index >= 0) { focusIndex = index; } } List setFocusList = new List(); private int focusIndex = 0; private void NewFundsPassword_OnKeyDown(object sender, KeyEventArgs e) { PasswordBox password = sender as PasswordBox; if (e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9) { if (password != null && password.Password.Length > 5) { e.Handled = true; return; } e.Handled = false; } else if (e.Key >= Key.D0 && e.Key <= Key.D9) { if (password != null && password.Password.Length > 5) { e.Handled = true; return; } e.Handled = false; } else { e.Handled = true; return; } } private void ConfFundsPassword_OnKeyDown(object sender, KeyEventArgs e) { PasswordBox password1 = sender as PasswordBox; if (e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9) { if (password1 != null && password1.Password.Length > 5) { e.Handled = true; return; } e.Handled = false; } else if (e.Key >= Key.D0 && e.Key <= Key.D9) { if (password1 != null && password1.Password.Length > 5) { e.Handled = true; return; } e.Handled = false; } else { e.Handled = true; } } } }