Exemplo n.º 1
0
        public CcPassword(ViewModels.AccountPasswordViewModel vm)
        {
            InitializeComponent();

            vm.LoginAccount  = "Not need input LoginAccount"; // 本界面只需输入密码
            this.DataContext = this.ViewModel = vm;

            this.Loaded += (s, e) =>
            {
                // CcSingleTextBox 需要对预设值进行 Foucs 与 SelectAll
                // 在 Loaded 事件,TextBox.Text 仍然是空值,故无法对全选 TextBox

                // 权宜之计 采用 BackgroundWorker 等待 100 毫秒
                if (mBgWorker != null && mBgWorker.IsBusy == true)
                {
                    return;
                }

                mBgWorker         = new System.ComponentModel.BackgroundWorker();
                mBgWorker.DoWork += (bgSender, bgArgs) =>
                {
                    System.Threading.Thread.Sleep(100);
                };

                mBgWorker.RunWorkerCompleted += (bgSender, bgResult) =>
                {
                    txtPassword.Focus();
                    txtPassword.SelectAll();
                };

                mBgWorker.RunWorkerAsync(new object[] { });
            };
        }
Exemplo n.º 2
0
        public CcAccountPassword(ViewModels.AccountPasswordViewModel vm)
        {
            InitializeComponent();
            this.DataContext = this.ViewModel = vm;

            this.Loaded += (s, e) =>
            {
                // CcSingleTextBox 需要对预设值进行 Foucs 与 SelectAll
                // 在 Loaded 事件,TextBox.Text 仍然是空值,故无法对全选 TextBox
                // 但 账号密码 这个控件无需进行全选操作

                var dataContext = this.DataContext as ViewModels.AccountPasswordViewModel;

                if (string.IsNullOrEmpty(dataContext.LoginAccount))
                {
                    txtLoginAccount.Focus();
                }
                else
                {
                    txtPassword.Focus();
                }
            };
        }