public static UIElement[] EnumerateUIElements(DependencyObject root) { List <UIElement> uiElements = new List <UIElement>(); UIFunctions.EnumerateUIElements(root, uiElements); return(uiElements.ToArray()); }
private static void EnumerateUIElements(DependencyObject root, List <UIElement> uiElements) { var uiRoot = root as UIElement; if (uiRoot != null) { uiElements.Add(uiRoot); } int count = VisualTreeHelper.GetChildrenCount(root); for (int i = 0; i < count; i++) { DependencyObject current = VisualTreeHelper.GetChild(root, i); UIFunctions.EnumerateUIElements(current, uiElements); } ; }
private void BuildTextBoxesMap() { this.mTextBoxesMap = new Dictionary <string, TextBox>(); this.mResetValidationMap = new Dictionary <string, PropertyInfo>(); var notificationsPropertyMap = DataTypeFactory.Current.GetNotifications(typeof(Contractor)); var lengthLimits = DataTypeFactory.Current.MaxLength(typeof(Contractor)); var elements = UIFunctions.EnumerateUIElements(this.ucRoot); var textBoxesBind = UIFunctions.GetTextBoxesWithBindedText(elements); foreach (var textBoxBind in textBoxesBind) { this.mTextBoxesMap.Add(textBoxBind.Item2, textBoxBind.Item1); int maxLength; if (lengthLimits.TryGetValue(textBoxBind.Item2, out maxLength)) { textBoxBind.Item1.MaxLength = maxLength; } PropertyInfo info; if (notificationsPropertyMap.TryGetValue(textBoxBind.Item2, out info)) { if (string.IsNullOrEmpty(textBoxBind.Item1.Name)) { throw new ArgumentNullException(); } this.mResetValidationMap.Add(textBoxBind.Item1.Name, info); textBoxBind.Item1.TextChanged += this.ResetTextBox_InvalidState; } } }