• 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.        }  
  • 相关阅读:
    scratch资源
    如何把scratch转成一个swf文件或者exe执行文件
    perl的匿名引用
    perl的内置函数scalar
    perl内置特殊变量查询
    Win7中安装Windows PowerShell 3.0
    man-pages项目包含文档的说明
    编译器思维之结合律
    Android中利用jsoup解析html页面
    MVP+Retrofit+RxJava
  • 原文地址:https://www.cnblogs.com/sjqq/p/8666660.html
Copyright © 2020-2023  润新知