Use LogicalTreeHelper to Validation
来源:互联网 发布:淘宝售前客服岗位职责 编辑:程序博客网 时间:2024/06/05 03:26
public class Validator { // Validate all dependency objects in a window public static bool IsValid(DependencyObject node) { // Check if dependency object was passed if (node != null) { // Check if dependency object is valid. // NOTE: Validation.GetHasError works for controls that have validation rules attached bool isValid = !Validation.GetHasError(node); if (!isValid) { // If the dependency object is invalid, and it can receive the focus, // set the focus if (node is IInputElement) Keyboard.Focus((IInputElement) node); return false; } } // If this dependency object is valid, check all child dependency objects foreach (object subnode in LogicalTreeHelper.GetChildren(node)) { if (subnode is DependencyObject) { // If a child dependency object is invalid, return false immediately, // otherwise keep checking if (IsValid((DependencyObject) subnode) == false) return false; } } // All dependency objects are valid return true; } }
private void BtnSave_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (Validator.IsValid(this)) { e.Handled = false; } else { e.Handled = true; } } private void UserControl_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { if (Validator.IsValid(this)) { e.Handled = false; } else { e.Handled = true; } } }
0 0
- Use LogicalTreeHelper to Validation
- how to use Commons Validator’s declarative validation framework
- Adding Validation to the Model
- How To Use DataGird
- First to use Blog!
- how to use typedef
- how to use gz
- How to use chkconfig
- How to use ,,,,
- CheckLinks To Use Spider
- To use MessageBox
- Why to use JSON?
- how to use dialog
- How to use UIDs
- How to use dmalloc
- How to use abld
- How to use BSTR
- Begin to use Blog
- BP神经网络
- JAVA学习总结12
- MySQL关键字,主关键字,候选关键字
- 文件相关的操作函数
- JAVA事件1
- Use LogicalTreeHelper to Validation
- 汇编语言二
- JAVA事件2
- 求组合数(取模)的两种方法
- Android Multimedia框架总结(十二)CodeC部分之OMXCodec与OMX事件回调流程
- 知道怎么停止很重要!!!
- CMD 命令行中的 tree 样式输出
- 遍历卷(GetLogicalDrivesStrings函数 、 FindFirstVolume函数 和 FindNextVolume函数)
- Android RecyclerView 使用完全解析 体验艺术般的控件