zoukankan      html  css  js  c++  java
  • WPF 在TextBox失去焦点时检测数据,出错重新获得焦点解决办法

    WPF 在TextBox失去焦点时检测数据,出错重新获得焦点解决办法 


    在WPF的TextBox的LostFocus事件中直接使用Focus()方法会出现死循环的问题


    正确的使用方式有2中方法:


    方法一:

    [csharp] view plain copy
     
    1. private void textBox3_LostFocus(object sender, RoutedEventArgs e)  
    2.         {  
    3.             if (textBox3.Text != "abc")  
    4.             {  
    5.                this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Render,  
    6.                new Action(() =>  
    7.                {  
    8.                    textBox3.Focus();  
    9.                }));  
    10.             }  
    11.         }  

    方法二,使用LostKeyboardFocus方法:
    [csharp] view plain copy
     
    1. private void textBox3_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)  
    2.        {  
    3.            if (textBox3.Text != "abc")  
    4.            {  
    5.                textBox3.Focus();  
    6.            }  
    7.        }  
  • 相关阅读:
    springBoot 与 springMVC的区别
    spring的IOC和AOP
    实现同步的三种方法
    台阶积水问题
    requsets模块和beautifulsoup模块
    爬虫
    rabbitMQ 消息队列
    Django框架
    mysql
    jQuery
  • 原文地址:https://www.cnblogs.com/sjqq/p/8666660.html
Copyright © 2011-2022 走看看